Exception in thread "main" java.lang.NoClassDefFoundError

Discussion in 'Java' started by Roubles, Oct 22, 2004.

  1. Roubles

    Roubles Guest

    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
     
    Roubles, Oct 22, 2004
    #1
    1. Advertising

  2. Roubles

    Tony Morris Guest

    Tony Morris, Oct 22, 2004
    #2
    1. Advertising

  3. Roubles wrote:
    > #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.
     
    Michael Borgwardt, Oct 22, 2004
    #3
  4. Michael Borgwardt <> scribbled the following:
    > Roubles wrote:
    >> #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


    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 () ------------- Finland --------\
    \-------------------------------------------------------- rules! --------/
    "You can pick your friends, you can pick your nose, but you can't pick your
    relatives."
    - MAD Magazine
     
    Joona I Palaste, Oct 22, 2004
    #4
  5. Joona I Palaste wrote:
    >>>I have a 'main' defined in GameOfLife.java. What am I missing ?

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

    >
    >
    > 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:
    >
    >>java -cp . org.eclipse.lifegame.domain.GameOfLife


    Presumably that is what was intended, but it still wouldn't work
    because there is no directory structure corresponsing to the packages.
     
    Michael Borgwardt, Oct 22, 2004
    #5
  6. Roubles

    Sudsy Guest

    Roubles wrote:
    > Hi All,

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

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

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
     
    Sudsy, Oct 22, 2004
    #6
  7. Roubles

    Roubles Guest

    > > Hi All,
    > <snip>
    > > #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
    >
    > <snip>
    > > #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


    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
     
    Roubles, Oct 22, 2004
    #7
  8. Roubles

    Sudsy Guest

    Roubles wrote:
    <snip>
    > 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.

    --
    Java/J2EE/JSP/Struts/Tiles/C/UNIX consulting and remote development.
     
    Sudsy, Oct 22, 2004
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page