Results 1 to 13 of 13
  1. #1
    bhupal4all's Avatar
    bhupal4all is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Thumbs down Exception in thread "main" java.lang.NoClassDefFoundError

    Hi,

    >>Demo.java
    public class Demo
    {
    public static void main(String args[])
    {
    System.out.println("Hello...");
    }
    }

    > javac Demo.java
    compilied successfuly and class file got generated.

    > java Demo
    Then i am getting
    "Exception in thread "main" java.lang.NoClassDefFoundError".

    I set java/bin folder in path variable.

    Could you tell me why am i getting this error and how can I solve this?

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    After the compilation check that Demo.class file is created or not in the same location of your source file is located.

    Did you working on any Java IDE?

  3. #3
    bhupal4all's Avatar
    bhupal4all is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Default

    No, I am not working on IDE. I have checked for class file. Its is there in current directory. But i am not able to run it.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Other than that in the code there is no any issue also, so it must run well. Just type javac and see what happen on the command prompt, I hope you are working on Windows platform.

  5. #5
    bhupal4all's Avatar
    bhupal4all is offline Member
    Join Date
    Sep 2008
    Posts
    13
    Rep Power
    0

    Default

    Yes, I am working on Windows Vista. I compiled it, but I didnt get any error.
    When I use 'javap', it is showing the content properly.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    If you are in the same directory as your class file (and it does not have a package) then you need to include "." (current directory) on your classpath
    Java Code:
    java -cp . Demo

  7. #7
    sagarbirari is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    IN Environment variable CLASSPATH add (.) means current working directory
    like this
    your_prev_path;.;

    Regards

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,874
    Rep Power
    25

    Default

    Here's what I get when I execute the java command with a non existant class file:

    D:\JavaDevelopment\Testing>dir asdf
    Volume in drive D is Work
    Volume Serial Number is 1463-F5AE

    Directory of D:\JavaDevelopment\Testing

    File Not Found

    D:\JavaDevelopment\Testing>java asdf
    Exception in thread "main" java.lang.NoClassDefFoundError: asdf
    part of the error message includes the class name. You left that part off your post.
    Can you try executing the dir command followed by java command then copy and paste the output here?

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Anyway that class file is missing in the location he/she run the code. As far as I know that's the only situation where NoClassDefFoundError come across.

  10. #10
    hemadri.niit is offline Member
    Join Date
    Sep 2008
    Posts
    1
    Rep Power
    0

    Default

    HI...
    WHEN JVM CANNOT ABLE TO FIND THE .class file . THEN WE WILL GET THIS ERROR .."Exception in thread "main" java.lang.NoClassDefFoundError".SO WHILE EXECUTING i mean to say drive_name java class file name...checkout drive name or folder name...etc

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    In compilation *.class file is created in the same file *.java file located. Unless you change the working folder on the command prompt after compilation, it don't effect to this exception anyway.

  12. #12
    Join Date
    Jun 2012
    Posts
    1
    Rep Power
    0

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

    Hi ,

    what is mentioned by masijade is working fine ie. java -cp . filename

    is working in command propmt of windows. This is because my .java and .class files are in the same directory.

    Thanks and Regards,
    Manish Gupta

  13. #13
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,585
    Rep Power
    12

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

    Thanks for the confirmation and the lengthy consideration.

    Closing the thread.

Similar Threads

  1. Replies: 8
    Last Post: 09-18-2008, 01:55 PM
  2. Replies: 6
    Last Post: 08-18-2008, 07:44 AM
  3. Replies: 1
    Last Post: 08-07-2007, 08:10 AM
  4. Replies: 1
    Last Post: 08-06-2007, 07:07 AM
  5. Replies: 2
    Last Post: 08-01-2007, 06:26 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
  •