• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Cannot get FXMLLoader to not create errors loading fxml files from resource root in IntelliJ

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to load an FXML file from a folder marked as a resource root in IntelliJ. I have tried multiple different things, but I cannot seem to figure it out.

The path to my fxml file is: <Project Directory> / res / fxml_files (designated as resource root) / game_screen.fxml

I've tried using these code samples and many others.


How can I get my FXML file to load properly?

Application sub-class



fxml file


Error Thrown

 
Phil Patterson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still not sure why my program didn't work before, but I managed to fix it by using an InputStream object instead of an URL.

Though that worked for me, I had to manually set stylesheets="@/game.css" in the fxml file to allow the program to find the css file associated with it. SceneBuilder did not produce a suitable argument for this. My css files were also in a resource root directory.

Here is my reworked program:
 
Sheriff
Posts: 6128
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect your resource folder wasn't setup correctly, although I don't know IntelliJ very well, so I couldn't help you with that.  I have added this thread to the IntelliJ forum.  Maybe someone will comment on that.

The rule when finding a resource (if I remember correctly) is that if the path starts with a slash (/) the path is relative to the classpath.  If it doesn't not start with a slash, the resource is relative to the current directory, usually the project directory.

You can use this debugging method to check what are the entries in the classpath for a resource name.  You can change the logger references to System.out.println() if you like:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!