Solved

running java GUI in linux console

Posted on 2002-05-22
39
625 Views
Last Modified: 2010-05-18
hi experts, l'm using redhat linux 7.2 and defaultly booting to run level 3 that without boot into GNOME or KDE. when i tried to ran my simple java GUI swing program just show out the helloworld text in windows, it return me an error message as following

Exception in thread "main" java.lang.internalError: can't connect to X11 window server using ':0.0' as value of the DISPLAY variable.
     at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
     at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:126)
     at java.lang.Class.forName0(Native Method)
     at java.lang.Class.forName(Class.java:130)
     at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
     at java.awt.Window.init(Window.java:208)
     at java.awt.Window.<init>(Window.java:252)
     at java.awt.Frame.<init>(Frame.java:398)
     at javax.swing.JFrame.<init>(JFrame.java:198)
     at mainform.main(mainform.java:6)

i expected it might be some sort of display setting need to be done in linux right ? or java ? please help......anyhelp would be appreciated. thanks.
0
Comment
Question by:Explorer060599
  • 15
  • 15
  • 5
  • +1
39 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
As the error states, you need to set the DISPLAY env var to the correct X Display.
I'm assuming X has already been started at this point.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Looking at it more closely :)  maybe X has not been started. In which case you need to start your Java app after X has been started.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
I would guess that, just as you can't run Java in DOS without Windows, you can't run Java in Linux without X.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
You certainly can run Java without X, however you obviously can't run AWT or Swing applications without X.
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
You're dead right objects - I've just proved as much!
0
 

Author Comment

by:Explorer060599
Comment Utility
iam been told that i can start x server or bring up the xterm to support java display GUI without goes into Windows Manager. itsn't true ?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
It certainly is possible to start X without starting a Window Manager.
But are you :-)
0
 

Author Comment

by:Explorer060599
Comment Utility
yeah, how to do that ?
0
 

Author Comment

by:Explorer060599
Comment Utility
yeah, how to do that ?somethin to do with xdm
0
 
LVL 92

Accepted Solution

by:
objects earned 100 total points
Comment Utility
Depends on your system. Your startup scripts would already have something in there to start X. Your probably just trying to start your GUI before it has happened.
xstart or something like that.

xdm is just a display manager, but it's usually one of the first thoings to get started after the server has started. So if you can find where xdm is started, you'll be pretty close to where the X server is started.

Starting up X w/out a winow manager will mean however that your windows will not have any frames.
0
 

Author Comment

by:Explorer060599
Comment Utility
i've tried run "X", it came out something like window manager but white blank screen with nothing. what is this ? itsn't this a X server ? what can i do in here ?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
If you want to be able to drag windows around, and resize them and perform these types of task then the X server is not enough, you'll also need the window manager started.
X is probably the X server binary, but running X alone is not a lot of use.
0
 

Author Comment

by:Explorer060599
Comment Utility
yeah right, so..isn't xdm the window manager as you said ?i've tried to put a very simple Java GUI in last line of public profile eg. "java simplegui", so the java GUI start up after user login. then i ran the "xdm" from console and window manager came out with nothing other than my java gui.but iam not able to move around the window and has no window frame with my java gui.looks weird. any idea ?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
No, xdm is a *display* manager, it is *not* a window manager..
An example of a window manager is mwm (motif).

> but iam not able to move around the window and has no window frame

That is because u are not running a window manager. It is the responsibility of the window manager to add frames to windows, and handle resizing & moving etc

Start up a window manager, mwm and twm are a couple of examples.
0
 

Author Comment

by:Explorer060599
Comment Utility
isn't GNOME and KDE desktop manager that run on top of twm ? i got error "twm:unable to open display" when ran "twm" from console. anything missing ? can i startup KDE or GNOME without any panel or icon other than my java GUI ?
0
 

Author Comment

by:Explorer060599
Comment Utility
somemore the right click menu and everything that able to configure.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
When u tried to run twm, was the X server running?
It needs to be running for the window manager to run.
Sorry I'm not very familiar with KDE or Gnome, but basically I think their just X apps, so they just need the X server to be running (and probably a window manager to be of any use).
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Try running 'startx' to start up X
0
 

Author Comment

by:Explorer060599
Comment Utility
when i ran "startx", it turned into GNOME. i was trying to put my java GUI in /etc/profile and set the runlevel to 5. when it was started, it booted into GNOME and my java GUI shown out on screen. but the things like i told you that "iam not able to move around the window and has no window frame with my java gui.looks weird". is like running xdm manually in console.i thing the linux start the sequence in following orders.

1.X server
2.xdm
3./etc/profile
4.GNOME desktop

that is why my java GUI shown out after xdm and before any desktop application like GNOME. am i right ? if then it must be some place to setup this order, right ?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:Explorer060599
Comment Utility
refer back to this error "i got error "twm:unable to open display". how to start the X server ? when i tried start X, it came out blank screen with nothing. what should i do then ?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Can I see your profile file pls.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
> how to start the X server ?

startx :-)

0
 
LVL 92

Expert Comment

by:objects
Comment Utility
I think what might be your problem, is that often the window manager is the last thing started. And it is started in the fg so that to log out you just have to quit the window manager.
So if you start something else (in the foreground) before it, then the window manager won't start until it finishes.
0
 

Author Comment

by:Explorer060599
Comment Utility
# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc


# Path manipulation
if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/sbin" ; then
    PATH=/sbin:$PATH
fi

if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/usr/sbin" ; then
    PATH=/usr/sbin:$PATH
fi

if [ `id -u` = 0 ] && ! echo $PATH | /bin/grep -q "/usr/local/sbin" ; then
    PATH=/usr/local/sbin:$PATH
fi

if ! echo $PATH | /bin/grep -q "/usr/X11R6/bin" ; then
    PATH="$PATH:/usr/X11R6/bin"
fi

# No core files by default
ulimit -S -c 0 > /dev/null 2>&1

USER=`id -un`
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"

HOSTNAME=`/bin/hostname`
HISTSIZE=1000

if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
    INPUTRC=/etc/inputrc
fi

EDDIE_HOME=/home/eddie/Java
JAVA_HOME=/usr/local/java/j2sdk1.4.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/utils.jar:$EDDIE_HOME/Test/Classes
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC JAVA_HOME PATH CLASSPATH

for i in /etc/profile.d/*.sh ; do
    if [ -r $i ]; then
         . $i
    fi
done

unset i
java mainform
0
 

Author Comment

by:Explorer060599
Comment Utility
here's my profile. my java GUI ran at last line. what should i do ?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
First thing to try would be to run it in the background.

java mainform &
0
 

Author Comment

by:Explorer060599
Comment Utility
u meant change the code "java mainform" in profile to "java mainform &" and reboot ?
0
 

Author Comment

by:Explorer060599
Comment Utility
yeah, now its running my java gui after GNOME desktop started. what next ?
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Is your window manager running?

(Did you're window manager EVER run?)

Sorry, I'm getting confused, whats the current problem and exactly what r we tryinbg to achieve?
0
 

Author Comment

by:Explorer060599
Comment Utility
what i wants is to run java gui after window manager like sawfish or twm without boot into GNOME desktop. i do not want user to have option by clicking anywhere and playing around the desktop setting.
0
 

Author Comment

by:Explorer060599
Comment Utility
i seeing sawfish (window manager) is running.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
OK so what you actually want to do is disable gnome starting up. Correct?
I'll see what I can find.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
No comment has been added lately, so it's time to clean up this TA.

I will leave a recommendation in the Cleanup topic area that this question is:

- To be deleted and points refunded

Please leave any comments here within the
next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

girionis
Cleanup Volunteer
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>- To be deleted and points refunded

Don't agree. People here deserve points (NOT me)
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 Do you believe that the problem is solved?
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
I believe people have invested time and effort in it. If points are now only being awarded for incontravertibly correct answers, a corollary to that would be that experts should not bother attempting to answer questions where a clear outcome cannot be guaranteed. Unless they have no interest in points of course.
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
 So the best would be to recommend a grade less than A (probably B), for comments that didn't absolutely solve the problem but gave considerable help, but unfortunatelly we do not have that option at the moment.

  In the past (and currently also) I have recommended comments to be accepted as answers to problems that are not quite solved but it can be infered that a comment was almost there. In this question however I cannot clearly deduce if the problem could have been solved although all the comments are to the point.

  I do not want to be unfair to objects as he already put much effort in this question but, on the other hand, I cannot also be unjust to the asker.

  I will leave it up to the moderator. If the moderator feels that points should be awarded they will be :-)
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Well, IMHO the principles should include:

1. Experts can contribute quite a lot without actually 'solving' the problem. Efforts should really be rewarded.
2. Questioners (this is really a reflection of the above) should *expect* to lose *some* points merely by asking a question.

These considerations become more important when the question is more complex, for reasons i gave on my last posting.
2. would also deter unfair behaviour on the part of questioners, as, actually, would a clear reminder to questioners that their points have been moved out of their account simply by asking the question (something i think a lot of people are not aware of)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now