0

When running my code in eclipse, it works flawlessly; however, when I export it, I get the "location is not set error" and don't understand why. This specific part of the code work every time in exports prio to me converting the project to a maven project.

Here is the code snippet that causes the error:

private static void showMainView() throws IOException {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(Main.class.getResource("MainGUI.fxml"));
    System.out.println(loader.getLocation());
    Main.mainLayout = loader.load();
    Scene scene = new Scene(mainLayout);
    Main.primaryStage.setScene(scene);
    Main.primaryStage.show();
}

Here is my file structure:

enter image description here

Here is the program working in the eclipse IDE with a print out of the file location

enter image description here

Here is the program error when troubleshooting in a powershell window with a print out of the file location being "null"

enter image description here

Could converting the project to a maven project have caused this? The reason I had to do this was the reflections library I'm using I could only find via a Maven dependency here https://github.com/ronmamo/reflections/tree/master

If more is needed to help troubleshoot, I'll provide it to the best of my ability, because this one has me stumped

James_D
  • 201,275
  • 16
  • 291
  • 322
  • 4
    See https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other, particularly the "Troubleshooting" section. Since you appear to be doing things correctly in the code you posted, I think the first thing I would check is the content of the jar file, to make sure the FXML file is there and is in the appropriate location (same place as `Main.class`). – James_D Jul 10 '20 at 19:09
  • 2
    no screenshots of text please, they are unreadable – kleopatra Jul 10 '20 at 21:23
  • @James_D I checked contents and found that when converted to a maven project, it separated any resources from jar files, and thus the paths were missing as they aren't in the same place anymore. My temporary fix was to change the "Included" option under project properties -> build path -> source to include all, and at least now it runs; however, it's still not working like it does in the IDE, so I guess I've got another headache to deal with – Derrick Lemmon Jul 13 '20 at 04:13

0 Answers0