-2

This problem occurred when I was trying to run a very simple program. The details are below:

    Caused by: java.awt.HeadlessException:
    No X11 DISPLAY variable was set,
    but this program performed an operation which requires it.
            at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:165)
            at java.desktop/java.awt.Window.<init>(Window.java:540)
            at java.desktop/java.awt.Frame.<init>(Frame.java:423)
            at java.desktop/java.awt.Frame.<init>(Frame.java:388)
            at java.desktop/javax.swing.JFrame.<init>(JFrame.java:180)
            at StdDraw.init(StdDraw.java:669)
            at StdDraw.<clinit>(StdDraw.java:632)
            ... 1 more

My OpenJDK version is "14.0.1" 2020-04-14

Qiuyu Li
  • 1
  • 2
  • For anyone who may encounter the same problem in the future, it turns out that the problem is because of WSL2. It needs some additional settings to run graphical programs. https://virtualizationreview.com/articles/2017/02/08/graphical-programs-on-windows-subsystem-on-linux.aspx – Qiuyu Li Oct 23 '20 at 14:01
  • Does this answer your question? ["No X11 DISPLAY variable" - what does it mean?](https://stackoverflow.com/questions/662421/no-x11-display-variable-what-does-it-mean) – TylerH Oct 23 '20 at 15:20
  • @QiuyuLi The fact you're executing this in WSL2 is very important information that should have been included in your question. – Mark Rotteveel Oct 24 '20 at 08:22

1 Answers1

3

I'm presuming you are running Linux or at the very least some form of Unix. That error states there is no X11 display. Either the system is 'head-less' meaning no GUI or perhaps even monitor OR you don't have X11 setup properly.

Now if you don't mean to use a GUI on this system then something in your java code is making a call to a SWING component. SWING is built on the older AWT which is why you are seeing both in the stack trace above.

Presuming you have the source code, step through the debugger to find the offending line of code and remove it. OR you need to setup a GUI on your Linux system.

sagneta
  • 1,546
  • 18
  • 26