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.
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:
^ This are the installations
^ 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!
Worked by openjdk for me:
On you host machine, enter: