jQuery in Action, 3rd edition
The moose likes Swing / AWT / SWT and the fly likes Getting error when running swing program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply locked New topic

Getting error when running swing program

saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
hi, i new to swing please help me

this is code:

import javax.swing.JFrame;
import javax.swing.JLabel;

//import statements
//Check if window closes automatically. Otherwise add suitable code
public class HelloWorldFrame extends JFrame {

public static void main(String args[]) {
new HelloWorldFrame();
HelloWorldFrame() {
JLabel jlbHelloWorld = new JLabel("Hello World");
this.setSize(100, 100);
// pack();

when i compiling

javac HelloWorldFrame.java

when i running
java HelloWorldFrame

Getting below error:

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:407)
at java.awt.Frame.<init>(Frame.java:402)
at java.awt.Frame.<init>(Frame.java:367)
at javax.swing.JFrame.<init>(JFrame.java:163)
at HelloWorldFrame.<init>(HelloWorldFrame.java:11)
at HelloWorldFrame.main(HelloWorldFrame.java:9)
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 43980
Please don't ask the same question twice.
I have already transferred you to the Linux forum because I don't think this is a Java problem at all.
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
I dont think this exception is related to Linux. You have written a code which requires a display. But your environment does not support a display.
Check your environment has all of them
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Getting error when running swing program
It's not a secret anymore!