It's not a secret anymore!
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


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(
at java.awt.Window.<init>(
at java.awt.Frame.<init>(
at java.awt.Frame.<init>(
at javax.swing.JFrame.<init>(
at HelloWorldFrame.<init>(
at HelloWorldFrame.main(
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46375
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 agree. Here's the link:
subject: Getting error when running swing program
It's not a secret anymore!