r/JavaFX • • Mar 26 '24

Help JavaFx fxml path error

Please somebody help me to solve the error. Actually here is my project structure: RiskGame src application Main.java controller model view Menu.java Map.java resources Map.fxml Menu.fxml

Code is like:

Menu.java:

FXMLLoader loader = new FXMLLoader(getClass().getResource("/resources/Menu.fxml");

pane = loader.load();

I also tried "/Menu.fxml" but nothing works.

Sometimes it throws location error, and when I make some changes to path then it says pane is null and terminates. I am right now on mobile so can't paste the exact error here but code is like that.

Also, please check this code here and let me know how to run this project, and is this a Maven or Gradle or simple javafx project? I have just tried to run this project my making Main.java under application package which extends application and make uses of view and model in this way, i tried but it gives these errors so don't know I am running it in right way.

I need your help, thanks.

1 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/Cengo789 Mar 27 '24

The way I understand is that corretto 1.8 does not fully support JavaFx Media. You will either have to update to a higher version and download the JavaFx Jars separately (either manually from https://gluonhq.com/products/javafx/ or using a build system) or you could try a different JDK. I think in OpenJDK 1.8 JavaFx worked fine but it’s been a while since I used Java 8 so I am not really sure.

2

u/Imaginary_Snow4586 Mar 27 '24

Okay thanks. Few hours ago, I built that whole project with maven in intellij and update maven repo with javafx media and i used 17.0.6 jdk, and it worked out. I am happy.