I am learning GUI in Java, and for that I have created a demo program:
import java.awt.*;
public class FrameDemo extends Frame {
public FrameDemo(){
Check what your environment variable DISPLAY's value is. Try running a simple X application from the command line. If it works, check DISPLAY's value for the right value.
You can experiment with different values of and environment variable on a per invocation basis by doing the following on the command line:
DISPLAY=:0.0 <your-java-executable-here>
How are you calling your program?
Check your X Window environment variables using the "env" command.
I stopped getting this exception when I installed default-jdk
using apt
. I'm running Ubuntu 14.04 (Trusty Tahr), and the problem appears to have been the result of having a "headless" Java installed. All I did was:
sudo apt-get install default-jdk
Ubuntu has the option to install a headless Java -- this means without graphics libraries. This wasn't always the case, but I encountered this while trying to run a Java text editor on 10.10 the other day. Run the following command to install a JDK that has these libraries:
sudo apt-get install openjdk-6-jdk
EDIT: Actually, looking at my config, you might need the JRE. If that's the case, run:
sudo apt-get install openjdk-6-jre
In my case
-Djava.awt.headless=true
was set (indirectly by a Maven configuration). I had to actively use
-Djava.awt.headless=false
to override this.
I would check with another Java implementation/vendor. Preferrably Oracle/Sun Java: http://www.java.com/en/ . The open-source implementations unfortunately differ in weird ways.