NoClassDefFoundError

Discussion in 'Java' started by John-FL, Oct 21, 2008.

  1. John-FL

    John-FL Guest

    Hey,

    I get a "NoClassDefFoundError" in my program when I call it using:
    java -classpath /path/to/program/ /path/to/program/Program
    > Exception in thread "main" java.lang.NoClassDefFoundError: /path/to/program/Program


    However, when I specify the path to the java program (relative), it
    works:
    java Program

    In both cases I am in the /path/to/program directory, and in there is
    Program.class and Program.java. Could someone let me know why this
    isn't working?

    Thanks!
    John
     
    John-FL, Oct 21, 2008
    #1
    1. Advertising

  2. John-FL

    Mark Space Guest

    John-FL wrote:
    > Hey,
    >
    > I get a "NoClassDefFoundError" in my program when I call it using:
    > java -classpath /path/to/program/ /path/to/program/Program
    >> Exception in thread "main" java.lang.NoClassDefFoundError: /path/to/program/Program


    What Eric said. In other words, if you have some class file, like:

    /path/to/program/mypack/Program.class

    and the Program class is defined like this:

    package mypack;
    public class Program {
    public static void main( String... args ) {
    // Do something
    }
    }

    The you want to run:

    java -cp /path/to/program mypack.Program

    Nothing else will do. You have to call the program by it's proper name
    ("mypack.Program") because the JVM won't run it if you specify a
    different name (which would be an incorrect name) and the classpath must
    point to the root of the hierarchy of the classes.

    If you can run your program just as java -cp Program then it's not in a
    package, but don't get confused. Even though packages names are
    converted into subdirectory names (so the loader can find them), package
    names are not changed by changing the directory that a class-file
    resides in. Package names are controlled by that "package" keyword
    above, and if your subdirectories don't match, it's an error.
     
    Mark Space, Oct 21, 2008
    #2
    1. Advertising

  3. John-FL

    mahaa_hth

    Joined:
    Oct 22, 2008
    Messages:
    4
    Location:
    india
    you have have to set classpath
     
    mahaa_hth, Oct 22, 2008
    #3
  4. John-FL

    mahaa_hth

    Joined:
    Oct 22, 2008
    Messages:
    4
    Location:
    india
    Please make sure whether you have set classpath .
    if not , set it . hope it will eork
     
    mahaa_hth, Oct 22, 2008
    #4
    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.
Similar Threads
  1. qazmlp
    Replies:
    6
    Views:
    13,558
    Joseph Millar
    Jul 11, 2003
  2. Monsieur Le Maire

    NoClassDefFoundError

    Monsieur Le Maire, Jul 21, 2003, in forum: Java
    Replies:
    2
    Views:
    445
    Roedy Green
    Jul 21, 2003
  3. netpro2k
    Replies:
    2
    Views:
    1,100
    netpro2k
    Aug 21, 2003
  4. keith
    Replies:
    0
    Views:
    324
    keith
    Oct 17, 2003
  5. Replies:
    1
    Views:
    2,219
    Irmen de Jong
    Jun 22, 2004
Loading...

Share This Page