Results 1 to 5 of 5
  1. #1
    Shujak is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default Jave Code Error : "main" java.lang.NoClassDefFound

    Plz have a look at the code snippet at Learn Java by Examples - How do I generate UUID / GUID?
    I am new to Java and need to run the UUID code snippet kept at above given link.
    Heres what i have done
    1.Installed jdk1.5.0_22
    2.Copied the code snippet into a file named RandomStringUUID.java and kept in C:\test
    3. Set the following user variables to
    CLASSPATH = C:\Program Files\Java\jdk1.5.0_22\lib
    JAVA_HOME = C:\Program Files\Java\jdk1.5.0_22\bin
    path = %path%;C:\Program Files\Java\jdk1.5.0_22\bin;

    4. From command prompt
    C:\Test>javac RandomStringUUID.java
    RandomStringUUID.class created

    5.From command prompt
    java RandomStringUUID

    i am getting the error
    Exception in thread "main" java.lang.NoClassDefFoundError: RandomStringUUID

    Can someone please help??

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Don't set the CLASSPATH environment variable. Instead, what if you call java with the class path parameter:

    Java Code:
    c:\Test>java -cp . RandomStringUUID

  3. #3
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Look at the first line of the source code of that class: it is in a package and you should use that when you try to run the compiled version of that class. Also, read your text book on packages and how to use them before you copy code, compile it and try to run it.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  4. #4
    Shujak is offline Member
    Join Date
    Jul 2011
    Posts
    2
    Rep Power
    0

    Default

    I removed the CLASSPATH environment variable
    Ran c:\Test>java -cp . RandomStringUUID
    And i got this error
    Exception in thread "main" java.lang.NoClassDefFoundError: RandomStringUUID (wrong name: org/kodejava/example/util/RandomStringUUID)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,431
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Shujak View Post
    I removed the CLASSPATH environment variable
    Ran c:\Test>java -cp . RandomStringUUID
    And i got this error
    Exception in thread "main" java.lang.NoClassDefFoundError: RandomStringUUID (wrong name: org/kodejava/example/util/RandomStringUUID)
    Reread my previous reply; your class is stored in a package so you should use the complete class name, not just its name RandomStringUUID. That's wht your JVM is complaining about.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 10
    Last Post: 07-20-2011, 02:11 PM
  2. Replies: 5
    Last Post: 06-22-2010, 03:51 PM
  3. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  4. Replies: 1
    Last Post: 08-07-2007, 07:10 AM
  5. Replies: 1
    Last Post: 07-25-2007, 10:55 PM

Posting Permissions

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