首页 > 解决方案 > 如何解决 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

标签: javajavafxjava-12

解决方案


正确的答案是--add-opens javafx.graphics/com.sun.javafx.text=ALL-UNNAMEDVM 选项。

但是,如果编写一个像这样的简单启动器类,任何人都可以避免这些 VM 选项:

public class AppLauncher {
    public static void main(String[] args) {
        YourAppMainClassNameHere.main(args);
    }
}

并通过它运行应用程序。


推荐阅读