Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error running code on Sun machine

0 views
Skip to first unread message

santosh

unread,
Apr 9, 2003, 4:15:12 PM4/9/03
to
Hi,
I am new to Java. I tried running this code from the OReilly book
"Learning Java":

import javax.swing.*;

public class HelloJava{
public static void main(String[] args){
JFrame frame = new JFrame("Hello Java!");
JLabel label = new JLabel("Hello Java!", JLabel.CENTER);
frame.getContentPane().add(label);
frame.setSize(300,300);
frame.setVisible(true);
}
}

This code ran easily on Windows but when I tried to run it on my
univ's Sun machines I got the following errors:

Exception in thread "main" java.lang.InternalError: Can't connect to
X11 window
server using ':0.0' as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:1
26)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvi
ronment.java:62)
at java.awt.Window.init(Window.java:223)
at java.awt.Window.<init>(Window.java:267)
at java.awt.Frame.<init>(Frame.java:398)
at javax.swing.JFrame.<init>(JFrame.java:198)
at HelloJava.main(HelloJava.java:5)

Can someone tell me why this is happening?

Thanks,
Santosh

Dave Glasser

unread,
Apr 9, 2003, 11:02:17 PM4/9/03
to
santo...@yahoo.com (santosh) wrote on 9 Apr 2003 13:15:12 -0700 in
comp.lang.java.help:

Did you launch the program from a bare login shell, rather than an
xterm window? If so, then you need to get your graphical environment
started first. I can't give you much help there, but you might try the
command:

startx

which usually works in Linux. If not, ask how to start an X desktop on
Solaris (I assume that's what your Sun box is running) in any Unix
newsgroup, or at the help desk in your schools computer lab, and you
should get help.

If you already have an X desktop running, and you're running the
command to start your program from an xterm window, then maybe it's
your DISPLAY environment variable. Try these commands before you
launch your program

DISPLAY=127.0.0.1:0.0
export DISPLAY

and it might help.


----
Check out QueryForm, a free, open source, Java/Swing-based
front end for relational databases.

http://qform.sourceforge.net

santosh

unread,
Apr 11, 2003, 12:35:14 PM4/11/03
to
Thanks Dave. You did point me in the right direction. I havent still
been able to correct the problem yet but I am working on it.

Santosh

Dave Glasser <dgla...@pobox.com> wrote in message news:<947CDB7C2A35C1E0.54B0EB13...@lp.airnews.net>...

Franck Lefebure

unread,
Apr 11, 2003, 2:20:40 PM4/11/03
to
If you don't want to run any x-server on your sun
(good way for a production machine) add this param
to your java process :
-Djava.awt.headless=true

Franck

"santosh" <santo...@yahoo.com> a écrit dans le message de news:
6484d538.03040...@posting.google.com...

Dave Glasser

unread,
Apr 11, 2003, 8:57:46 PM4/11/03
to
"Franck Lefebure" <fle...@orange.gp.nospam> wrote on Fri, 11 Apr 2003
14:20:40 -0400 in comp.lang.java.help:

>If you don't want to run any x-server on your sun
>(good way for a production machine) add this param
>to your java process :
>-Djava.awt.headless=true

He needs an X server to display his app's JFrame though. My
understanding is that that the java.awt.headless property is only used
to simulate a headless environment, probably so you can test code to
make sure it will run in a headless environment before deploying it as
a Unix daemon or Windows service. For more info:

http://mindprod.com/jglossheadless.html

Dave Glasser

unread,
Apr 11, 2003, 9:02:19 PM4/11/03
to
santo...@yahoo.com (santosh) wrote on 11 Apr 2003 09:35:14 -0700 in
comp.lang.java.help:

>Thanks Dave. You did point me in the right direction. I havent still
>been able to correct the problem yet but I am working on it.

You're welcome, glad I could help. BTW, are you telnetting into that
Sun machine, or actually sitting down in front of it? If you're
telnetting in, you'll have to have the X server running on whatever
box you're telnetting from, which is probably a Windows box. A lot of
universities, I imagine, have X server software installed on their
Windows machines, but again you'll have to have someone knowledgeable
help you.

0 new messages