Getting a HeadlessException: No X11 DISPLAY variable was set
Asked Answered
C

6

36
Exception in thread "main" java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
        at java.awt.Window.<init>(Window.java:432)
        at java.awt.Frame.<init>(Frame.java:403)
        at javax.swing.JFrame.<init>(JFrame.java:202)
        at DrawGUI.<init>(DrawGUI.java:15)
        at ShapeCreator.<init>(ShapeCreator.java:31)
        at ShapeCreator.main(ShapeCreator.java:138)

What does this error message mean? And how can I solve it?

Canaigre answered 7/3, 2011 at 11:3 Comment(3)
You have to set the DISPLAY environment variable to the address of your X11 server, e.g. DISPLAY=localhost:0.0, before starting your Java application.Montane
I have the same issue, and my DISPLAY variable is correctly set and exported - I can start up an 'xterm' with no issue for instance. Must be something else going on here as well....Barnaby
Great answer @Raphael B to a terribly vague question. Sorted my issue on the Raspberry Pi which wasn't setting DISPLAY when startx was called.Jeanette
P
21

I assume you're trying to tunnel into some unix box.

Make sure X11 forwarding is enabled in your PuTTY settings.

enter image description here

Phiz answered 7/3, 2011 at 11:5 Comment(0)
B
4

This appears to be a more general SWING/AWT/JDK problem that just the JBOSS installer:

The accepted answer below solved the issue for me :

Unable to run java gui programs with ubuntu

("sudo apt-get install openjdk-6-jdk")

Barnaby answered 25/9, 2012 at 9:35 Comment(0)
F
2

Your system does not have a GUI manager. Happens mostly in Solaris/Linux boxes. If you are using GUI in them make sure that you have a GUI manager installed and you may also want to google through the DISPLAY variable.

Fireback answered 7/3, 2011 at 11:5 Comment(1)
"GUI Manager" is not the word you're after. It's an X11 Server. And barely having it installed is not enough. You'd need it running and you need to have DISPLAY set accordingly.Nealson
M
2

I think you are trying to run some utility or shell script from UNIX\LINUX which has some GUI. Anyways

SOLUTION: dude all you need is an XServer & X11 forwarding enabled. I use XMing (XServer). You are already enabling X11 forwarding. Just Install it(XMing) and keep it running when you create the session with PuTTY.

Mertz answered 25/3, 2015 at 7:41 Comment(0)
N
1

In my case it was not a problem with the display server or a window manager on my Arch Linux. Other GUI apps launched without a hitch from terminal. After a little digging I decided to print out all the system properties (System.getProperties()) and realized that the JVM (java executable) I was using was not from the JDK downloaded from Oracle's website but from the one supplied by my system's package manager.

Apparently, my system had headless version of openjdk installed. The JVM supplied by this openjdk package had no support for display and peripheral devices, hence headless. That's why I was getting the HeadlessException.

Some folks suggest to install the regular version of openjdk where JVM runs in non-headless mode unless instructed to do otherwise. Other solution is to always use JVM from the JDK you downloaded from Oracle. I chose the latter.

I setup an alias in my bash to java keyword.

alias java="/path/to/downloaded/jdk/bin/java "

I then tested the graphics capabilities of both JVMs with this code:

import java.awt.GraphicsEnvironment;

// Inside main method:
System.out.println(GraphicsEnvironment.isHeadless());

The above code printed true when executed with system's JVM and printed false when executed with downloaded JVM. My actual code using Swing ran fine too.

Nephrotomy answered 4/4, 2023 at 17:0 Comment(1)
This worked wonders for me. I accidentally only had the headless version installed. Thank you!Invagination
F
0

Problem statement – Getting java.awt.HeadlessException while trying to initialize java.awt.Component from the application as the tomcat environment does not have any head(terminal).

Issue – The linux virtual environment was setup without a virtual display terminal. Tried to install virtual display – Xvfb, but Xvfb has been taken off by the redhat community.

Solution – Installed ‘xorg-x11-drv-vmware.x86_64’ using yum install xorg-x11-drv-vmware.x86_64 and executed startx. Finally set the display to :0.0 using export DISPLAY=:0.0 and then executed xhost +

Fulgent answered 10/1, 2013 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.