0

I'm having a problem with JavaFX FMXL loading files in my project and also started to learn IntelliJ. So, I've imported a simple, SceneBuilder project from my GitHub to IntelliJ, but when I start to run the application, I got the "location is not set" exception. In the screenshot below I'm showing the code and my project path: enter image description here

Here's the error code:

java.lang.IllegalStateException: Location is not set.
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2434)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
    at mouseClicker.SwitchScene.moveToMainWindow(SwitchScene.java:28)
    at mouseClicker.App.start(App.java:16)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)

However, the exacly same code works for me in Eclipse, which I also have just installed on this computer:

enter image description here

How is this possible? Does this mean that my code isn't somehow portable to other IDEs or even worse, will not work at all at some environmental circumstances and if yes, what is the good practice to avoid such situations in the future?

Jack_Russell
  • 323
  • 5
  • 20
  • 1
    "*[...] what is the good practice to avoid such situations in the future?*" - Use a build system that is independent from your IDE, e.g. ant, maven or gradle. – Turing85 Mar 02 '18 at 10:39
  • 1
    this is a maven project, you can see the pom.xml file in the second screenshot – Jack_Russell Mar 02 '18 at 10:42
  • 1
    a) Don't use relative paths. They won't work in a jar file. Perhaps one of the IDEs runs creates a jar file and runs the app from that file... In this case the absolute path is shorter anyway. b) make sure the resources are included in the build. Some IDEs apply a filter. – fabian Mar 02 '18 at 10:52
  • so how should this path look like? are you saying I should use absolute paths e.g. C://Program Files:/workspace/project? – Jack_Russell Mar 02 '18 at 11:47
  • [Don't post code as images](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-on-so-when-asking-a-question). – James_D Mar 02 '18 at 12:13
  • In this case I would just do `load(MainWindowController.class.getResource("MainWindow.fxml"))` – James_D Mar 02 '18 at 12:21

0 Answers0