Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to run different java-swing programs, which used to run before, but I can't start them from the commandline, without getting this error:

java GuessGame
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11GraphicsEnvironment
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:112)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at java.awt.Toolkit$2.run(Toolkit.java:849)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:841)
at sun.swing.SwingUtilities2$AATextInfo.getAATextInfo(SwingUtilities2.java:121)
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1564)
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:147)
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1599)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:530)
at javax.swing.UIManager.setLookAndFeel(UIManager.java:570)
at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1320)
at javax.swing.UIManager.initialize(UIManager.java:1407)
at javax.swing.UIManager.maybeInitialize(UIManager.java:1395)
at javax.swing.UIManager.getDefaults(UIManager.java:644)
at javax.swing.UIManager.getString(UIManager.java:790)
at javax.swing.UIManager.getString(UIManager.java:807)
at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:476)
at javax.swing.JOptionPane.showInputDialog(JOptionPane.java:442)
at IO.input(GuessGame.java:10)
at Player.createPlayer(GuessGame.java:26)
at GuessGame.init(GuessGame.java:52)
at GuessGame.main(GuessGame.java:85)

I don't show the source, because it used to run before, as well as a dozen other programs, and wasn't changed.

You might google for the error-message, and find the advice, to start java in headless mode. This doesn't apply here, because there, the idea is, to do graphics stuff on a server, maybe to produce a chart or convert a graphic, which usually needs a display. Then you may specify 'headless', because nothing get's displayed on the server. Here it is the opposite: I want my frame to be displayed, and I have a DISPLAY=:0.0, where my xterm (xfce4 for instance) is running. I even may start ecliplse from the menu.

Similar, the advice unset DISPLAY doesn't fit form me for the very same reason. I need to use the display, and it is up and responsive - I'm using Firefox right now on that machine.

echo $DISPLAY
:0.0

Trying to run from a special input like the verve-comamndline doesn't work either.

It's a mystery to me. Xorg.0.log doesn't show something interesting either.

share|improve this question
1  
just a guess, are you using sun-java-6? –  steabert Apr 11 '11 at 13:57
    
java version "1.6.0_18" OpenJDK Runtime Environment (IcedTea6 1.8.1) (6b18-1.8.1-0ubuntu1) OpenJDK Client VM (build 16.0-b13, mixed - mode) (Answer fast, this looks like an upvote + accepted) ... –  user unknown Apr 11 '11 at 14:38
1  
that's not sun java, maybe that is the problem. You could try installing the package sun-java6-jre (sudo aptitude install sun-java6-jre) and then set your default java using sudo update-alternatives --config java and choose the one from sun as default. EDIT: I completely missed reading your answer below, so I guess that's already exactly what you did... –  steabert Apr 11 '11 at 16:27
    
Not exactly. Sun-Java was already installed, but not the primary Java. But of course it is only a workaround. A workaround I can live with, but a workaround. –  user unknown Apr 11 '11 at 16:34

1 Answer 1

up vote 2 down vote accepted

I didn't remember that I had OpenJDK activated on this computer, and switched to it recently.

After steaberts comment, I found the solution real quick:

update-java-alternatives -l
java-1.5.0-sun 53 /usr/lib/jvm/java-1.5.0-sun
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun

^ This are the installations

sudo update-java-alternatives -s java-6-sun

^ switched to suns java (formerly known as oracle :) )

and: Bingo: No more error-message, program runs.

If somebody has a solution for OpenJDK: You're welcome. But I'm not that much interested anymore and wouldn't spend hours of tests on this. :)

However: you rock!

share|improve this answer
    
Yup, I used this: -Djava.awt.headless=true –  Aki Sep 27 '13 at 15:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.