JavaFX模块javafx.graphics [英] JavaFX module javafx.graphics
问题描述
在解决robot.awt的一个必需问题之后,我现在在运行我的应用程序时遇到了另一个问题.应用程序构建没有问题.堆栈跟踪:
Upon fixing a requires issue with robot.awt I've now encountered another problem upon running my application. Application builds with no issues. Stack trace :
Exception in Application constructor
Exception in thread "main" 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:566)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class reports.Main
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:890)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class reports.Main (in module Reports) because module Reports does not export reports to module javafx.graphics
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$8(LauncherImpl.java:802)
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.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
Process finished with exit code 1
推荐答案
此问题的根本原因包含在以下行中:
The root cause for the issue is contained in this line:
Caused by: java.lang.IllegalAccessException: class com.sun.javafx.application.LauncherImpl (in module javafx.graphics) cannot access class reports.Main (in module Reports) because module Reports does not export reports to module javafx.graphics
Application.launch
使用反射使用反射创建应用程序类的实例.如果外部类位于打开或导出到Application
的模块(javafx.graphics
)的程序包中,则仅允许外部类(例如Application
)通过反射访问您的类.
Application.launch
uses reflection to create a instance of the application class using reflection. External classes like Application
are only allowed to access your classes via reflections if the class recides in a package that is opened or exported to Application
's module (javafx.graphics
).
您需要在Reports
模块声明中添加以下行之一:
You need to add one of the following lines your Reports
module declaration:
exports reports;
opens reports to javafx.graphics;
最后一行应该是首选,因为它是限制性更强的一行.如果除非reports
软件包中还包含例如main
类/方法,您应该使用第一行.
The last line should be preferred since it's the more restrictive one. If the unless the reports
package also contains e.g. a main
class/method, you should use the first line.
这篇关于JavaFX模块javafx.graphics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!