6

I am using InteliJ, I've gone through all other solutions that seem to work for everybody else. I was getting an error:

Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5782d366) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x5782d366

I then added the following to VM options in the run config:

--module-path="C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib" \ 
    --add-modules=javafx.controls \
    --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED \
    --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED \
    --add-exports=javafx.base/com.sun.javafx.beans=ALL-UNNAMED \
    --add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED \
    --add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED

That seemed to partially fix the problem? Howerver when I try to run this I don't get a whole stack trace of errors, I get these three lines:

"C:\Program Files\Java\jdk-11.0.1\bin\java.exe" \
    --module-path=C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib \
    --add-modules=javafx.controls,javafx.fxml \
    --add-exports=javafx.graphics/com.sun.javafx.util=ALL-UNNAMED \
    --add-exports=javafx.base/com.sun.javafx.reflect=ALL-UNNAMED \
    --add-exports=javafx.base/com.sun.javafx.beans=ALL-UNNAMED \
    --add-exports=javafx.graphics/com.sun.glass.utils=ALL-UNNAMED \
    --add-exports=javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED \
    --add-modules javafx.base,javafx.graphics \
    --add-reads javafx.base=ALL-UNNAMED \
    --add-reads javafx.graphics=ALL-UNNAMED \
    "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3\lib\idea_rt.jar=60572:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.3\bin" \
    -Dfile.encoding=UTF-8 \
    -classpath C:\Users\mresp_000\Desktop\Business\Code\VirtualBeats\out\production\VirtualBeats;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\src.zip;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx-swt.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.web.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.base.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.fxml.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.media.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.swing.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.controls.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.graphics.jar \
    -p C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.base.jar;\
        C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib\javafx.graphics.jar \
    virtualbeats.Main
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found

Process finished with exit code 1

I get the same error when I only put in the following to the VM options:

--module-path="C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib"
--add-modules=javafx.controls,javafx.fxml

Here is a picture of my run options (I have ticked and un-ticked the "include dependencies withg provided scope" box, neither work.

The library is pointing to the right place and I've tried rebuilding the project, nothing is working. When I go to my command line and type:

dir "C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib"

I get the following output: output of cmd

So everything is infact there and pointing to the exact location it needs to be pointing to. Adding the .jar extension to the add-module also does nothing.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
MahBoi
  • 61
  • 1
  • 6
  • @JoséPereda but the error sounds misleading, isn't it? What's the root cause for that? I meant the IllegalAccessError one. – Naman Dec 04 '18 at 16:26
  • 2
    @Mehdi - This is where you can start off with using openjfx - https://openjfx.io/openjfx-docs/#introduction from Java11 onwards. – Naman Dec 04 '18 at 16:27
  • @nullpointer yes my bad, I didn't understand the question initially – Mehdi Dec 04 '18 at 16:29
  • @nullpointer Right, probably this [question](https://stackoverflow.com/questions/53447738/java-fx-modular-application-module-not-found-java-11-intellij) will help as well. It is a mixture of both issues. – José Pereda Dec 04 '18 at 16:31
  • @JoséPereda Thanks. Not very satisfied with that either. I can understand by the error that the module `javafx.controls` has not been resolved on the module path, but then the question is why even after explicitly specifying is the module not resolved? The [`--show-module-resolution`](https://stackoverflow.com/questions/48339598/list-the-modules-resolved-during-the-application-startup) would be useful here to see what modules are getting resolved. – Naman Dec 04 '18 at 16:54
  • 1
    @nullpointer the exception itself is related to a wrong path for the JavaFX library. Nevertheless the module `javafx.fxml` should be added as well. – José Pereda Dec 04 '18 at 17:00
  • @JoséPereda Thanks for pointing that out, however it does not change anything. I still get the same error. – MahBoi Dec 04 '18 at 21:47
  • Can you open a terminal and type `dir "C:\mypath\SDKS\javafx-sdk-11.0.1\lib"` and post the result (or a screenshot), obviously with your real path? – José Pereda Dec 04 '18 at 23:28
  • @JoséPereda I have edited the post and added the output from that command – MahBoi Dec 05 '18 at 02:07
  • Please, add an edit to your question, and post the exception you get when you run with only these VM options: `--module-path="C:\User\..\javafx-sdk-11.0.1\lib" --add-modules=javafx.controls,javafx.fxml`. Also you could add a screenshot of your IntelliJ's Run configuration. – José Pereda Dec 06 '18 at 20:42
  • @JoséPereda it is done – MahBoi Dec 07 '18 at 02:27
  • Ok, you wouldn't need the `--add-exports` now, but that won't change it. When you run your project from IntelliJ, you still get the same failure right?. Check the run window (Alt+4) and post the full command line that IntelliJ generates (if you see something like `..\jdk-11\bin\java.exe...` click on the ellipsis to get the full command line). – José Pereda Dec 07 '18 at 09:23
  • @JoséPereda edited the post – MahBoi Dec 07 '18 at 18:00
  • Thanks, after editing your command line I see the reason why it is failing: you have an extra `-p`, that means the same as `--add-module`, which is invalidating the first one, and only adds base and graphics, but not controls and fxml. The question is why you have this `-p` added. Can you remove all the `--add-exports` and check again? You shouldn't get that extra `-p`. – José Pereda Dec 07 '18 at 18:17
  • I tried again and it didn't work. I think I will just build it with maven or gradle – MahBoi Dec 08 '18 at 02:32

2 Answers2

1

Try:

--module-path C:\Users\mresp_000\Desktop\Business\Code\SDKS\javafx-sdk-11.0.1\lib --add-modules=ALL-MODULE-PATH

as Runconfiguration, I don't know, maybe it works?

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
0

Alternatively, convert your project to Maven, then add the JavaFX dependencies as:

<!-- JavaFx -->
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>15</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>15</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-graphics </artifactId>
            <version>15</version>
            <classifier>win</classifier>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>15</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>15</version>
        </dependency>

        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>15</version>
        </dependency>

         <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-swing</artifactId>
            <version>15</version>
        </dependency>

Change the version according to your used Java Version, since anything above Java 10 does not include the JavaFX libraries, this is what I recommend if you want to deploy your application on other machines anyway

Dahlin
  • 157
  • 1
  • 11