java - 如何解决 Java 中的“模块 javafx.graphics 不会“打开 com.sun.javafx.text”到未命名模块”问题?
问题描述
我在用
jdk12,javafx12
和日食ide。当我运行我的代码时,它应该创建一个窗格、一个文本字段和一些按钮。它只是创建窗格然后我得到一个错误
我尝试使用
jdk11
我得到了同样的错误
我把这些写给
VM
论据:
--module-path /home/beyza/openjfx-12.0.1_linux-x64_bin-sdk/javafx-sdk-
12.0.1/lib
--add-modules javafx.controls
--add-modules javafx.base
--add-modules javafx.graphics
--add-modules javafx.fxml
--add-modules javafx.media
--add-exports javafx.graphics/com.sun.javafx.util=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.util=ALL-UNNAMED
--add-exports javafx.base/com.sun.javafx.logging=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.prism=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.glass.ui=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.geom.transform=ALL-
UNNAMED
--add-exports javafx.graphics/com.sun.javafx.tk=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.glass.utils=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.font=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
--add-exports javafx.controls/com.sun.javafx.scene.control=ALL-
UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene.input=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.prism.paint=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.scenario.effect=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.text=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.geom=ALL-UNNAMED
--add-exports javafx.graphics/com.sun.javafx.scene.text=ALL-UNNAMED
--add-opens javafx.graphics/javafx.scene=ALL-UNNAMED
--add-opens javafx.graphics/javafx.scene.text=ALL-UNNAMED
我收到了这个错误
Exception in thread "JavaFX Application Thread"
java.lang.ExceptionInInitializerError
Caused by: java.lang.reflect.InaccessibleObjectException: Unable
to make private int
com.sun.javafx.text.PrismTextLayout.getLineIndex(float)
accessible: module javafx.graphics does not "opens
com.sun.javafx.text" to unnamed module
解决方案
正确的答案是--add-opens javafx.graphics/com.sun.javafx.text=ALL-UNNAMED
VM 选项。
但是,如果编写一个像这样的简单启动器类,任何人都可以避免这些 VM 选项:
public class AppLauncher {
public static void main(String[] args) {
YourAppMainClassNameHere.main(args);
}
}
并通过它运行应用程序。
推荐阅读
- tensorflow - Tensorflow Estimators:serving_input_fn 和 input_fn 有什么区别
- java - 从不同类的单独方法调用包含 throw InterruptedException 的方法
- android - 添加模块后无法识别类符号
- visual-studio-2017 - Visual Studio 2017 中的 OpenFileDialog 组件
- javascript - 有没有办法在谷歌应用脚本中创建自定义按钮?
- glsl - 线性化深度
- xml - XSLT 应用模板,其中子元素以“A”开头
- python - Pandas - 遍历 groupby df 并按交集过滤
- sql-server - 涉及 Null 和空白与填充值的复杂 SQL Server Pivot
- html - Angular 6 routerLinkActive 不起作用