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(){         super("Frame Demo");         setSize(200, 200);         setVisible(true);     }      public static void main(String args[]){         new FrameDemo();         } }   It was compiled successfully. But when I tried to execute the program, I found the following error:
Exception in thread "main" java.awt.HeadlessException     at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:173)     at java.awt.Window.<init>(Window.java:437)     at java.awt.Frame.<init>(Frame.java:419)     at FrameDemo.<init>(FrameDemo.java:4)     at FrameDemo.main(FrameDemo.java:9)   I am using Xubuntu 10.10 and java -version gives:
java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.5) (6b20-1.9.5-0ubuntu1) OpenJDK Client VM (build 19.0-b09, mixed mode, sharing)   What should I to do?
One more thing: It is the same sort of error I got when I tried to execute Dr. Java and HJSplit's jar file.
The Java Runtime Environment (JRE) is required to run Java programs. Nowadays there are many JRE packages available from a variety of projects and companies, but the two most popular on Ubuntu are OpenJDK and Oracle HotSpot.
In Java applications, the components that comprise a GUI (Graphical User Interface) are stored in containers called forms. The Java language provides a set of user interface components from which GUI forms can be built.
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 
                        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 
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With