我正在使用
jdk12,javafx12
和eclipse ide。当我运行我的代码时,它应该创建一个 Pane 、一个文本字段和一些按钮。它只是创建了 Pane ,然后我得到了一个错误
我尝试使用
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);
}
}
并通过它运行应用。
关于java - 如何修复 "module javafx.graphics does not "在 Java 中打开 com.sun.javafx.text“to unnamed module”的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56900737/