【问题标题】:JavaFX non-modular project Graphics Device initialization failed for : d3d, sw Error initializing QuantumRenderer: no suitable pipeline foundJavaFX非模块化项目图形设备初始化失败:d3d,sw初始化QuantumRenderer时出错:找不到合适的管道
【发布时间】:2021-02-20 15:04:30
【问题描述】:

我正在尝试让 JavaFX 在具有非模块化项目的 Windows 10 上运行。我有 Java 版本 14.0.1 和 JavaFX 版本 15.0.1。我完全按照here 列出的说明进行操作,但是当我运行程序时,它给了我这个错误:

Graphics Device initialization failed for :  d3d, sw
Error initializing QuantumRenderer: no suitable pipeline found
java.lang.RuntimeException: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer.getInstance(QuantumRenderer.java:280)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:244)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:261)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    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:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Error initializing QuantumRenderer: no suitable pipeline found
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:94)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:124)
    at java.base/java.lang.Thread.run(Thread.java:832)
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:564)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: No toolkit found
    at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:273)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:267)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:158)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:658)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:409)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    ... 5 more

我也看过这些问题(123),我按照他们说的做了,但运行时仍然出错。我从official download website下载了JavaFX sdk文件,我的VM选项是:

--module-path "C:\Program Files\Java\javafx-sdk-15.0.1\lib" --add-modules=javafx.controls,javafx.fxml 

我尝试将模块路径更改为不同位置的路径以及没有空格的路径,但均无济于事。我也尝试过使用 Eclipse、Netbeans 和没有 IDE(所有设置说明都来自 the official website),但它们都不起作用。我试图运行的程序只是一个测试程序。

package sample;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;

public class Main extends Application {
    @Override
    public void start(Stage primaryStage) {
        try {
            // create a new Text shape
            Text messageText = new Text("Hello World! Lets learn JavaFX.");

            // stack page
            StackPane root = new StackPane();

            // add Text shape to Stack Pane
            root.getChildren().add(messageText);

            Scene scene = new Scene(root,400,400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        launch(args);
    }
}

编辑:对答案的回应

抱歉回复晚了,但我试着把你说的放在虚拟机选项里,我想这就是你的意思,但是我收到了一个错误

Error: Could not find or load main class run.jvmargs=--module-path
Caused by: java.lang.ClassNotFoundException: run.jvmargs=--module-path.

我也尝试在没有 run.jvmargs= 的情况下运行它,但它也不起作用。我收到以下错误。

Error: Could not find or load main class \
Caused by: java.lang.ClassNotFoundException: \

顺便说一下,我所拥有的特定 VM 选项如下。

run.jvmargs=--module-path "C:\\Program Files\\Java\\javafx-sdk-15.0.1\\lib" \
    --add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web \
    --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED \
    --add-exports=javafx.web/com.sun.webkit.network=ALL-UNNAMED \
    --add-exports=javafx.web/com.sun.webkit.dom=ALL-UNNAMED \
    --add-exports=javafx.graphics/com.sun.scenario.animation.shared=ALL-UNNAMED \
    --add-exports=javafx.graphics/com.sun.javafx.tk.quantum=ALL-UNNAMED

编辑 - 2:

【问题讨论】:

    标签: java intellij-idea javafx runtime-error


    【解决方案1】:

    我的项目也使用这个 run.jvmargs 属性。 HTere的

    run.jvmargs=--module-path "D:\\Libraries\\Java9\\openjfx-13.0.2_windows-x64_bin-sdk\\javafx-sdk-13.0.2\\lib" \
        --add-modules=javafx.base,javafx.controls,javafx.fxml,javafx.graphics,javafx.media,javafx.swing,javafx.web \
        --add-exports=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED \
        --add-exports=javafx.web/com.sun.webkit.network=ALL-UNNAMED \
        --add-exports=javafx.web/com.sun.webkit.dom=ALL-UNNAMED \
        --add-exports=javafx.graphics/com.sun.scenario.animation.shared=ALL-UNNAMED \
        --add-exports=javafx.graphics/com.sun.javafx.tk.quantum=ALL-UNNAMED // <<-- notice this thing
    

    另外,请确保您使用的是 \\ 而不是 \

    【讨论】:

    • 您好,谢谢您的回复。不幸的是,我仍然对您的 VM 选项有错误。我在问题的底部编辑了详细信息。如果你不介意,可以请你看一下吗?
    • 嗨,@yakatoi,该文件中有另一个参数称为main.class,我认为您应该将其设置为sample.Main,以与您用于启动项目的应用程序类相对应。作为验证者,您应该使用this.getClass().getName() 来获取该字符串。
    • 感谢您的回复!我对你的意思有点困惑。你说的是程序中的包名还是项目的文件结构?如果是关于文件结构,我在问题中有一张照片。如果它与包名有关,我将其从 sample 更改为 sample.main。但什么也没发生。
    • 更新!我有点解决了这个问题,不是真的。我刚刚切换到 Java SE 8 因为我相当肯定我正在从事的项目可以使用 SE8。一种临时解决方案,但它有效。感谢您的所有帮助!
    • 对,所以java使用包。这些与文件夹结构相对相似。如果您在文件夹A 中有一个文件夹X,其中包含C 类,它将是X.A.C ... XApackages。当您编译/运行程序时,类路径编译器使用文件夹结构来建立类的路径......因此它将定义它的 X.A.C 用于实例化 C 类的路径。因为您使用 C 类来运行应用程序......您需要在project.properties 文件中将X.A.C 引用设置为main.class
    猜你喜欢
    • 2016-09-11
    • 2021-04-20
    • 1970-01-01
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    • 2014-02-06
    • 1970-01-01
    相关资源
    最近更新 更多