0

So everything was working just fine before the reinstall. I pushed to git naturally then I reinstalled my OS. After the reinstall, when I try to run the JavaFx application, I get the IllegalStateExceptionL: Location is not set

Is there any reason why this is happening? It worked before and now it isn't. My folder structure is like this:

src:
   main:
       java:
           com.package:
                      Launcher.java
       resources:
           com.package:
                      main.fxml

And this is how I get the resource in my Launcher.java class:

  URL resource = getClass().getResource("main.fxml");

What I've tried:

When I sout the resource, (obviously) null is returned. I have also checked and verified that my resources is marked as the resources root in Project Structure.

I have also tried changing the path to /main.fxml but this doesn't work also. I feel like I shouldn't be even changing the code and maybe Intellij is missing something? But anyways I'm just confused as to why this is happening all of a sudden. Not sure if this is a duplicate since its a common error but I want to know why it just stopped working.

Any help would be appreciated

(The only thing that's changed from the previous set up is the Java version. I was on JDK14 previously and I'm using 15 now.)

The stacktrace is :

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:832)
Caused by: java.lang.IllegalStateException: Location is not set.
    at javafx.fxml/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2459)
    at javafx.fxml/javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
    at MyApplication.main/com.package.Launcher.start(Launcher.java:21)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    ... 1 more
Exception running application com.package.Launcher

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Launcher.main()'.```
  • 1
    Check the content of the build folder. – James_D Oct 28 '20 at 13:03
  • Please share the stacktrace. Also, we don't know what "the" JavaFX application is so relevant code would help. – Michel Jung Oct 28 '20 at 14:01
  • @James_D the build folder shows the file `build -> resources -> main -> com -> package -> main.fxml` – carlo_webber124 Oct 28 '20 at 15:51
  • @MichelJung I made an edit with the stacktrace. As for the code, its just the main Launcher for my application. I can show the class too but its just your regular JavaFX FXML loading for the `main` method – carlo_webber124 Oct 28 '20 at 16:01
  • Is your project a Java module? If so, `getClass().getResource("main.fxml")` might not work (I can't explain why). And is your project started via Gradle? – Michel Jung Oct 28 '20 at 16:11
  • The build looks wrong to me. `Launcher.class` should be in the same folder (in the build/output structure) as `main.fxml`?. – James_D Oct 28 '20 at 16:41
  • @MichelJung yes it is a Gradle modular project. It was working before though – carlo_webber124 Oct 28 '20 at 16:51
  • @James_D Anything I can do to rectify the build? – carlo_webber124 Oct 28 '20 at 16:53
  • I'd clean and rebuild it first. Then check gradle settings (I'm not a gradle user). – James_D Oct 28 '20 at 16:55
  • Just tried that, no dice. Are you on Maven? I can try switching to it and see if it compiles – carlo_webber124 Oct 28 '20 at 16:58
  • What version of Gradle are you using? Can you share your `build.gradle[.kts]` file? And to clarify, does your code have a `module-info.java` file? – Slaw Oct 28 '20 at 21:04
  • @Slaw here's the `build.gradle` file from the [repo](https://github.com/kawaki-san/DigitalAssistant/blob/master/build.gradle). And yes, I have a `module-info.java` file. Grade is `gradle-6.5.1-all` – carlo_webber124 Oct 28 '20 at 21:26

0 Answers0