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?
posted 1 week ago
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.
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:
All things are lawful, but not all things are profitable.