javafx.controls could not be found JavaFX 11 / JDK

2020-03-02 07:41发布

问题:

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:

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.