Welcome to Dream.In.Code
Become a Java Expert!

Join 149,824 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,594 people online right now. Registration is fast and FREE... Join Now!




Can't use javax.swing.JOptionPane with jdk in Linux?

 
Reply to this topicStart new topic

Can't use javax.swing.JOptionPane with jdk in Linux?

Israel
20 Feb, 2007 - 07:55 PM
Post #1

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Ok, I'm using Knoppix 5.1 and everytime I try to compile a source with jdk that has import javax.swing.JOptionPane; I get an error like this:

CODE
Exception in thread "main" java.lang.InternalError: Can't connect to X11 window server using ':0' as the value of the DISPLAY variable.
        at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at sun.awt.X11GraphicsEnvironment.access$000(X11GraphicsEnvironment.java:53)
        at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:142)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:131)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:164)
        at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:68)
        at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:96)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:164)
        at java.awt.Toolkit$2.run(Toolkit.java:821)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:804)
        at javax.swing.UIManager.initialize(UIManager.java:1262)
        at javax.swing.UIManager.maybeInitialize(UIManager.java:1245)
        at javax.swing.UIManager.getUI(UIManager.java:851)
        at javax.swing.JOptionPane.updateUI(JOptionPane.java:1810)
        at javax.swing.JOptionPane.<init>(JOptionPane.java:1773)
        at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:831)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:645)
        at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:616)
        at Welcome.main(Welcome.java:5)
root@Me:/home/Israel/Java#  


Any suggestions?
User is offlineProfile CardPM
+Quote Post

ReggaetonKing
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 08:21 PM
Post #2

D.I.C Head
Group Icon

Joined: 16 Nov, 2006
Posts: 73



Thanked: 1 times
Dream Kudos: 100
My Contributions
Post your code and I will see where the error is coming from.
User is offlineProfile CardPM
+Quote Post

Israel
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 08:31 PM
Post #3

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Here's one of many:
CODE
import javax.swing.JOptionPane;

public class Welcome {
  public static void main(String[]args){
  JOptionPane.showMessageDialog(null, "Welcome to Java",
  "Display Message", JOptionPane.INFORMATION_MESSAGE);
  }
}


User is offlineProfile CardPM
+Quote Post

Abbygail
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 09:52 PM
Post #4

D.I.C Head
**

Joined: 13 Jul, 2006
Posts: 61


My Contributions
Are you running it from konsol or are you using a terminal (like the ones accessible by pressing crtl+alt+F1) if you are running it from a ctrl-alt-F1 type terminal then you will get an error because it cannot access X11 (X11 is usually of ctrl-alt-F7) but if I remember knoppix has if on ctrl-alt-F5... Therefore you need to be running it from a konsol type application. Other wise you will definitely be getting this error.

User is offlineProfile CardPM
+Quote Post

ReggaetonKing
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 10:20 PM
Post #5

D.I.C Head
Group Icon

Joined: 16 Nov, 2006
Posts: 73



Thanked: 1 times
Dream Kudos: 100
My Contributions
Although I have no experience with Live Linux distros. Sorry I could not help. Seems like Abbygail got it though!
User is offlineProfile CardPM
+Quote Post

Israel
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 10:34 PM
Post #6

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Well, I should have mentioned that I have Knoppix installed to my hard drive. I know that it can run a little different from the live cd. But I tried using Crtl+alt+F5 and Crtl+alt+F7 and saw no results? Still have the same errors. Like I said, I know things run different when the distro is installed though....
User is offlineProfile CardPM
+Quote Post

Abbygail
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 10:38 PM
Post #7

D.I.C Head
**

Joined: 13 Jul, 2006
Posts: 61


My Contributions
QUOTE(Israel @ 20 Feb, 2007 - 11:34 PM) *

Well, I should have mentioned that I have Knoppix installed to my hard drive. I know that it can run a little different from the live cd. But I tried using Crtl+alt+F5 and Crtl+alt+F7 and saw no results? Still have the same errors. Like I said, I know things run different when the distro is installed though....


Are you in kde???
User is offlineProfile CardPM
+Quote Post

Israel
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 11:21 PM
Post #8

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
Yeah...
User is offlineProfile CardPM
+Quote Post

Abbygail
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
20 Feb, 2007 - 11:30 PM
Post #9

D.I.C Head
**

Joined: 13 Jul, 2006
Posts: 61


My Contributions
QUOTE(Israel @ 21 Feb, 2007 - 12:21 AM) *

Yeah...

then u opening a konsole/terminal from there and run the app??
If so you should not have any issues..

User is offlineProfile CardPM
+Quote Post

Israel
RE: Can't Use Javax.swing.JOptionPane With Jdk In Linux?
21 Feb, 2007 - 07:58 AM
Post #10

D.I.C Addict
Group Icon

Joined: 21 Nov, 2004
Posts: 626


Dream Kudos: 175
My Contributions
No... that's what I've been doing and this is where the original error I posted came from.

EDIT: Ok, I just got some advice from a Knoppix forum and it ran. You have to use an X-terminal. Not the normal command line shell. Thanks for the help! Hopefully this will help someone else who is lost.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:20AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month