Results 1 to 3 of 3
  1. #1
    carl is offline Member
    Join Date
    Jul 2007
    Posts
    35
    Rep Power
    0

    Default Exception in thread "main" java.lang.NoClassDefFoundError

    Hi, I'm on a WinXP PC and got java installed in C:\j2sdk1.4.2_06
    I've set the PATH environment variable to point to C:\j2sdk1.4.2_06\bin
    I'm getting an error message all the time when trying to run my classes:
    Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
    I suspect this is coming from not setting the CLASSPATH.
    Where should the CLASSPATH point to?
    Thanks

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Posts
    135
    Rep Power
    0

    Default

    This should be in the FAQ. No disrespect to you Carl. Every new Java user hits this one.
    If you compile a class MyClass.java in the current directory and then want to run it, try the following:
    >java -cp . MyClass

    The "-cp ." is the key here. It tells Java to add the current directory to the classpath when running.

    The other reason for this error is that your class file is myclass.java instead of MyClass.java. Java - unlike windows - is very picky about the case of the files.

  3. #3
    Swamipsn is offline Member
    Join Date
    Jul 2007
    Posts
    74
    Rep Power
    0

    Default

    In environment variable try this
    PATH C:\j2sdk1.4.2_06\bin

    Otherwise try to compile from command prompt and set
    CLASS PATH = C:\j2sdk1.4.2_06\bin

    Make sure in command prompt your in source directory or not?

Similar Threads

  1. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  2. Replies: 1
    Last Post: 08-06-2007, 06:07 AM
  3. Replies: 1
    Last Post: 07-31-2007, 01:54 PM
  4. Replies: 1
    Last Post: 07-25-2007, 10:55 PM
  5. Replies: 1
    Last Post: 07-16-2007, 06:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •