Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 15 of 15

Thread: NoClassDefFound

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default NoClassDefFound

    I am writing a Java project, with public static void main in ClassMain class and somehow get this NoClassDefFoundError (before, evereything worked correctly).

    java.lang.NoClassDefFoundError: ClassMain
    Caused by: java.lang.ClassNotFoundException: ClassMain
    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)
    Exception in thread "main"

    I found something at Bug ID: 6434149 (cl) ClassLoader.loadClass() throws java.lang.ClassNotFoundException: [Ljava.lang.String; in JDK 6.0 but I do not know where to change this -Dsun.lang.ClassLoader.allowArraySyntax=true I am using Eclipse.

    Any help please?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    How are you executing the java class? What command are you using?
    Is there a class named ClassMain? Has it been successfully compiled and is there a ClassMain.class file where the java command can see it (ie its on the classpath)?

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: NoClassDefFound

    I have a class named ClassMain name in my project but it does not compile (folder "Bin" does not contain any of .class files)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    You won't be able to execute the program without a .class file.

    it does not compile
    If there are errors, copy and paste the full text here.

  5. #5
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: NoClassDefFound

    This is complete code I am talking about (project also contains a heap of other classes, none of them containing main method.

    import java.io.FileNotFoundException;
    import java.io.IOException;
     
     
     
    public class MainClass{
     
     public static void main(String[] args) throws IOException,FileNotFoundException,ClassNotFoundException{
     
     
     
    		System.out.println("Does not work!!!");
    	}}

    2-3 days ago I had same problem Then I just put static void main into another class and it was then again ok. Today I have written some of documentation and created JavaDOC and after that (till now) this does not work. Putting static void main into another class also does not help.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    Sorry, I was referring to the error message. Please copy and paste the full text of the error message here.

    One observation:
    java.lang.NoClassDefFoundError: ClassMain
    vs
    public class MainClass{

    The class names shown are different.

  7. #7
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: NoClassDefFound

    That's just my typo (with ClassMain and MainClass (names are same)) Sorry for that.

    Message in console is that one from my first post and it also shows one frame with name "Java Virtual Machine Launcher" and message Could not find main class: ClassMain Program will exit.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    Where is the the file: ClassMain.class?
    Open a comand prompt, change to the folder holding the ClassMain.class file and issue the command:
    java ClassMain
    This should start your program executing.
    If not, copy and paste the contents of the screen here.
    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.

  9. The Following User Says Thank You to Norm For This Useful Post:

    Javabeginner (August 27th, 2010)

  10. #9
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: NoClassDefFound

    As I have written previously, there is none ClassMain.class !!! I have just ClassMain.java written in eclipse editor and normally in project folder i have bin and src folders and bin is just empty

  11. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    Then you must compile it to create a .class file.

  12. #11
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: NoClassDefFound

    If Eclipse hasn't compiled (aka built) the classes for you, go to Project->Build Automatically to let eclipse build it automatically for you. Alternatively, go to Project->Build Project. This should compile the classes for you.

  13. #12
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: NoClassDefFound

    That does not help Again "bin" folder is empty First time I got this problem I did not get solution (quickly) and I had to create new project and copy all classes to it and it started to work (no code change was done).
    Now I am 100 % sure that it is not up to me It worked (showed GUI), then I just changed text written on one of JLabels and now I get this error Could not find the main class etc...

  14. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    Can you successfully compile the program? Does it generate a .class file?

  15. #14
    Junior Member
    Join Date
    Aug 2010
    Posts
    23
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: NoClassDefFound

    That is problem I think It does not compile I used this copeg's suggestion and no error message is shown when I select Project->Build Project and I check "bin" folder that normally contains .class files and it is empty Very strange

  16. #15
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: NoClassDefFound

    You need to find a forum for your IDE and ask them how to configure it.