JavaFX 模块 javafx.graphics [英] JavaFX module javafx.graphics

查看:26
本文介绍了JavaFX 模块 javafx.graphics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在修复 robots.awt 的一个 requires 问题后,我现在在运行我的应用程序时遇到了另一个问题.应用程序构建没有问题.堆栈跟踪:

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 仅允许通过反射访问您的类,如果该类记录在打开或导出到 Application 的模块 (javafx.xml) 的包中.图形).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆