I\'m using IntelliJ IDEA 13.1.5, I used to work with Eclipse. I\'m working on JavaFX application, I try to load FXML file within my MainApp class using getClass().getResourc
I gave up trying to use
getClass().getResource("BookingForm.css"));
Instead I create a File object, create a URL from that object and then pass it into getStyleSheets() or setLocation()
File file = new File(System.getProperty("user.dir").toString() + "/src/main/resources/BookingForm.css");
scene.getStylesheets().add(folder.toURI().toURL().toExternalForm());
Windows is case-sensitive, the rest of the world not. Also an executable java jar (zip format) the resource names are case sensitive.
Best rename the file
view/RootLayout.FXML
to
view/RootLayout.fxml
This must be done by moving the original file away, and creating a new one.
Also compile to a jar, and check that the fxml file was added to the jar (zip file). When not IntelliJ resource paths are treated by an other answer.
By the way this is path relative to the package path of getClass()
. Be aware if you extended this class the full path changes, better use:
MainApp.class.getResource("view/RootLayout.fxml")
For those who use Intellij Idea: check for Settings -> Compiler -> Resource patterns
.
The setting contains all extensions that should be interpreted as resources. If an extension does not comply to any pattern here, class.getResource will return null for resources using this extension.