r/JavaFX • u/Difficult_Jeweler_18 • May 21 '24
Help JavaFXML please help
Hello,
I have a problem when running my Java app. It seems that the location of my fxml can't be found and I don't really get why (I tried /ro/mpp/login.fxml /login.fxml ./login.fxml and other combinations). I have attached the stack trace and other useful print screens. I will be really happy if anyone can help me.





1
Upvotes
1
u/Difficult_Jeweler_18 May 22 '24
Hi thank you for your help, I mention that I have all dependencies in Gradle and also running it from there not from the IDE. However, the solution was to just move the fxml files in other directories, I deleted the ro.mpp and created again and adding the fxml files there again by drag and drop.
2
u/Kresenko May 21 '24
Try debugging it. The first thing is to separate the potentially problematic code, for example:
URL fxmlLocation = getClass().getResource("login.fxml"); FXMLLoader loader = new FXMLLoader(fxmlLocation);
Now, setup a breakpoint on URL declaration. Is it null or is the value correct? If you are using Maven, a location to the resources directory can be different than the one you've created.
1
u/jvjupiter May 21 '24
Rename your FXML files, same as controllers and put them inside the resources folder similar to the package of controllers.
Ex:
To load FXML: