1

I get this error whenever I try to run a simple JavaFX program from vscode using WSL2 Ubuntu 20.04:

azazel@LAPTOP-R9S2TP63-wsl:~/Documents/java_projects/javafx$  /usr/bin/env /usr/lib/jvm/java-17-oracle/bin/java --module-path /home/azazel/javafx-sdk-17.0.1/lib --add-modules javafx.controls,javafx.fxml --enable-preview -XX:+ShowCodeDetailsInExceptionMessages -Dfile.encoding=UTF-8 @/tmp/cp_5i5aurl6hr3wctagqlxidgd8h.argfile App 
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:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1071)
Caused by: java.lang.UnsupportedOperationException: Unable to open DISPLAY
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$new$6(GtkApplication.java:181)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.<init>(GtkApplication.java:179)
        at javafx.graphics/com.sun.glass.ui.gtk.GtkPlatformFactory.createApplication(GtkPlatformFactory.java:41)
        at javafx.graphics/com.sun.glass.ui.Application.run(Application.java:146)
        at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:291)
        at javafx.graphics/com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:293)
        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

Here is the bottom of my .bashrc file:

#installing X11 for WSL
export DISPLAY=$(grep nameserver /etc/resolv.conf | awk '{print $2}'):0.0
export LIBGL_ALWAYS_INDIRECT=1
DISPLAY=:0.0
export DISPLAY

Here is my settings.json:

{
    "java.project.sourcePaths": ["src"],
    "java.project.outputPath": "bin",
    "java.project.referencedLibraries": [
        "lib/**/*.jar",
        "/home/azazel/javafx-sdk-17.0.1/lib/*.jar"
    ]
}

Here is my launch.json:

 "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "Launch Current File",
            "request": "launch",
            "mainClass": "${file}"
        },
        {
            "type": "java",
            "name": "Launch App",
            "request": "launch",
            "vmArgs": "--module-path /home/azazel/javafx-sdk-17.0.1/lib --add-modules javafx.controls,javafx.fxml",
            "mainClass": "App",
            "projectName": "javafx_ef467b58"
        }
    ]
}

Here is the actual code I am running:

import javafx.application.Application;
import javafx.stage.Stage;

public class App extends Application{
    public static void main(String[] args) throws Exception {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        // TODO Auto-generated method stub
        
        stage.show();

    }

    
}

I have installed VcXsrv and run it on Windows before running the application. Is this what I am supposed to do?

I have tried just about EVERYTHING I could find anywhere, but nothing is working. Does anyone know what's up?

Kai Strachan
  • 141
  • 1
  • 1
  • 4
  • 1
    First check you are exporting display environment variable (`export DISPLAY=:0`), also that GTK required OS dependencies are installed, also check you are not using a Headless Java Runtime. Check this post: https://stackoverflow.com/questions/5241850/running-java-gui-applications-through-a-linux-terminal/24247175 – Rafael Guillen Oct 25 '21 at 13:26
  • 1
    Does WSL2 support user interfaces? – Slaw Oct 25 '21 at 19:14
  • See also comments here https://stackoverflow.com/questions/64263232/internalerror-running-javafx-15-application-on-windows-subsystem-for-linux – DuncG Oct 25 '21 at 21:37
  • @RafaelGuillen Neither that nor the answers in the comments help. I will edit my post to show the environment variables and what exactly I am doing. – Kai Strachan Oct 27 '21 at 12:39

0 Answers0