Exception in thread "main" java.lang.NoClassDefFoundError

R

Roubles

Hi All,

I've been working on this project for a while now on Windows using
eclipse ... and eclipse magically launches my application, so
everything was dandy. Now I've brought my code over to a linux machine
and I can't seem to compile/run the java application.

#46 > ls
Cell.java GameOfLifeBoard.java GameOfLife.java RunButton.java

#47 > javac Cell.java GameOfLifeBoard.java GameOfLife.java
RunButton.java

#48 > ls
Cell.class Cell.java GameOfLife$1.class GameOfLifeBoard.class
GameOfLifeBoard.java GameOfLife.class GameOfLife.java
RunButton.class RunButton.java

#49 > java -cp . org/eclipse/lifegame/domain/GameOfLife
Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/lifegame/domain/GameOfLife

I have a 'main' defined in GameOfLife.java. What am I missing ?
Also, what is GameOfLife$1.class ?

tia,
rouble
 
M

Michael Borgwardt

Roubles said:
#48 > ls
Cell.class Cell.java GameOfLife$1.class GameOfLifeBoard.class
GameOfLifeBoard.java GameOfLife.class GameOfLife.java
RunButton.class RunButton.java

#49 > java -cp . org/eclipse/lifegame/domain/GameOfLife
Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/lifegame/domain/GameOfLife

I have a 'main' defined in GameOfLife.java. What am I missing ?

A Class named org/eclipse/lifegame/domain/GameOfLife
Also, what is GameOfLife$1.class ?

An anonymous inner class.
 
J

Joona I Palaste

A Class named org/eclipse/lifegame/domain/GameOfLife

No, what he is missing is the correct syntax. Java classnames use .
as the package separator. / is only for JVM internal use.
The correct command therefore is:
java -cp . org.eclipse.lifegame.domain.GameOfLife

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"You can pick your friends, you can pick your nose, but you can't pick your
relatives."
- MAD Magazine
 
M

Michael Borgwardt

Joona said:
No, what he is missing is the correct syntax.

That wouldn't help either.
What he is missing is a basic understanding of how Java's package
system works in regard to invocation of programs.
Java classnames use .
as the package separator. / is only for JVM internal use.
The correct command therefore is:

Presumably that is what was intended, but it still wouldn't work
because there is no directory structure corresponsing to the packages.
 
S

Sudsy

Roubles said:
#47 > javac Cell.java GameOfLifeBoard.java GameOfLife.java
RunButton.java

Assuming your source files contain lines like this:
package org.eclipse.lifegame.domain
then use this:

javac -d . Cell.java GameOfLifeBoard.java GameOfLife.java
RunButton.java

#49 > java -cp . org/eclipse/lifegame/domain/GameOfLife
Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/lifegame/domain/GameOfLife

java -cp . org.eclipse.lifegame.domain.GameOfLife
 
R

Roubles

Hi All,
Assuming your source files contain lines like this:
package org.eclipse.lifegame.domain
then use this:

javac -d . Cell.java GameOfLifeBoard.java GameOfLife.java
RunButton.java



java -cp . org.eclipse.lifegame.domain.GameOfLife

This worked beautifully (thanks to all that replied), on windows, but
on my linux system it hangs.

# javac -d . Cell.java GameOfLifeBoard.java GameOfLife.java
RunButton.java
# java -cp . org.eclipse.lifegame.domain.GameOfLife
Hello. Got this far.
Got this far 2.
Got this far 3.
[ctrl-c]
[root@dhcp-64-102-93-113 domain]#
# cat GameOfLife.java

package org.eclipse.lifegame.domain;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.text.NumberFormat;

public class GameOfLife {
public static void main(String[] args) {
System.out.println("Hello. Got this far.");

//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
GameOfLifeBoard b = new GameOfLifeBoard();
System.out.println("Got this far 2.");
b.displayGUI();
System.out.println("Got this far 3.");
}
});
}
}

No frame pops up. Nothing happens. I have ctrl-c the application.
Any Clue ?

tia,
rouble
 
S

Sudsy

Roubles wrote:
This worked beautifully (thanks to all that replied), on windows, but
on my linux system it hangs.

Probable cause: application cannot connect to the X11 server.
Either the server is not running (you haven't run the "startx" command)
or it's running under someone else's uid. In the latter case, do a "man
xhost" to figure out the command you need to run to permit other users
to connect to the server.
NOTE: The error message is not generated immediately. IIRC it can take
30 or 60 seconds to fail. Make sure that you don't ^C the app too
soon else you'll never see the message.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top