Java 10 JavaFX java.lang.IllegalAccessError

时间:2018-10-30 02:03:59

标签: java gradle javafx module java-10

我正在尝试将JavaFX Gradle项目更新为Java10。我已经更改了build.gradle文件,就像在this guide中一样。但是,当我尝试运行项目(执行./gradle run)时,出现此错误:

> Task :run FAILED
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:62)
        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:62)
        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:941)
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:844)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x5ce4f9a4) 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 @0x5ce4f9a4
        at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
        at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
        at com.project.example.Main.start(Main.java:16)
        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(Native Method)
        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.project.example.Main

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-10-openjdk/bin/java'' finished with non-zero exit value 1

因此,问题在于com.sun.javafx.fxml.FXMLLoaderHelper类无法访问com.sun.javafx.util.Utils类。是什么导致此问题,如何解决?

1 个答案:

答案 0 :(得分:0)

您必须将 Uncaught TypeError: Cannot read property 'top' of undefined at HTMLAnchorElement.<anonymous> (main.js:9) at HTMLAnchorElement.dispatch (jquery-3.4.1.min.js:2) at HTMLAnchorElement.v.handle (jquery-3.4.1.min.js:2) 模块添加到VM参数中。这样做,请按照下列步骤操作:

  

运行>>运行配置

将此行添加到VM参数:

javafx.fxml

确保在窗口的右侧选择了要运行的类。

有关更多信息,请访问JavaFX文档中的入门,位于以下链接:https://openjfx.io/openjfx-docs/#install-javafx