'Unable to run javafx project

I am getting the following error when I run the main file in the Javafx project:

C:\Users\monu\OneDrive\Documents\jdk-11.0.10\bin\java.exe --module-path C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib --add-modules javafx.fxml,javafx.controls,javafx.graphics --add-modules javafx.base,javafx.graphics --add-reads javafx.base=ALL-UNNAMED --add-reads javafx.graphics=ALL-UNNAMED "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\lib\idea_rt.jar=59212:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.3\bin" -Dfile.encoding=UTF-8 -classpath C:\D-drive\codage-aider\student\agbi\sample-github\C195\out\production\C195;C:\D-drive\libraries\mysql-connector-java-8.0.26.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx-swt.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.web.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.base.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.fxml.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.media.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.swing.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.controls.jar;C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib\javafx.graphics.jar main.java.C195
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:283)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.init(QuantumToolkit.java:254)
    at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:264)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:163)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:659)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:410)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    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: Error initializing QuantumRenderer: no suitable pipeline found
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.init(QuantumRenderer.java:95)
    at javafx.graphics/com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(QuantumRenderer.java:125)
    at java.base/java.lang.Thread.run(Thread.java:834)
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: No toolkit found
    at javafx.graphics/com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:276)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:163)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.startToolkit(LauncherImpl.java:659)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:410)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:364)
    ... 5 more

Process finished with exit code 1

In the run configurations in Intellij Idea the following is specified for the value of VM arguments : `--module-path "C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib" --add-modules javafx.fxml,javafx.controls,javafx.graphics`

I have included the necessary JavaFX lib folder and MySQL connector jar that I am using in my project, But strangely I still get this weird error.
I downloaded the SDK for windows from here https://gluonhq.com/products/javafx/ that's a little weird. I am not sure if I am missing anything. As I have followed all the steps from the JavaFX website. I am using a non-maven project here. Any ideas or hints on how
to proceed to debug this or fix it? Thanks



Minimal reproducible example :

 package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        primaryStage.show();
    }


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

sample.fxml :

<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>


The VM arguments in the Intellij is - --module-path "C:\D-drive\libraries\javafx-sdk-17.0.0.1\lib" --add-modules javafx.controls


This is a simple normal JavaFX program. There is some setup issue that is causing the problem because there cannot be a simpler program than this. It looks like no JavaFX project is working.
I am experimenting with non-maven projects only.


Solution 1:[1]

i have never worked with intellij, i work with eclipse, i had the same problem not while running from the ide but when i exported it as a jar. The thing is, the javafx sdk has a bin folder that contains several dll files, important for running the javafx app. The ide should use them once you add the libs to the build path, at least eclipse does that, make sure you have maintained the original folders in the sdk To avoid this kind of problems in the future, and avoid to manually add all the dlls when i export the jar, i created a new java runtime image, using jlink, that has all the javafx sdk built in it. This is the best option at least for me, if you want to go this way, you should download the javafx jmods and add them to the jmods folder in the jdk installation, after that you can create a new runtime image with jlink I'll edit this post later and add the jlink command line

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hamlet