Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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(
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(
at sun.awt.X11.XToolkit.<clinit>(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at java.awt.Toolkit$
at Method)
at java.awt.Toolkit.getDefaultToolkit(
at sun.swing.SwingUtilities2$AATextInfo.getAATextInfo(
at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(
at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(
at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(
at javax.swing.UIManager.setLookAndFeel(
at javax.swing.UIManager.setLookAndFeel(
at javax.swing.UIManager.initializeDefaultLAF(
at javax.swing.UIManager.initialize(
at javax.swing.UIManager.maybeInitialize(
at javax.swing.UIManager.getDefaults(
at javax.swing.UIManager.getString(
at javax.swing.UIManager.getString(
at javax.swing.JOptionPane.showInputDialog(
at javax.swing.JOptionPane.showInputDialog(
at IO.input(
at Player.createPlayer(
at GuessGame.init(
at GuessGame.main(

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.


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
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
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
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


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.