Results 1 to 5 of 5
  1. #1
    Teedo is offline Member
    Join Date
    Apr 2012
    Posts
    61
    Rep Power
    0

    Default Why would I get a NoClassDefFoundError exception when I didn't change anything?

    Hello,
    My program was working fine and then without changing anything, it has started throwing me a "Exception in thread "main" java.lang.NoClassDefFoundError: medina/client/ClientGameFrame". I'm dumbfounded as to how this can just suddenly appear after I've been working on this program all week. My research has pointed out that it must be my class paths but as far as I know, the class paths are fine....and why would it suddenly stop working if it was my class paths ?

    EDIT: I have just been trying to compile in netbeans and that's when the error occurs, though I just tried packaging to a jar and the jar works fine...though why not in netbeans?
    Last edited by Teedo; 02-23-2014 at 07:57 AM.

  2. #2
    Teedo is offline Member
    Join Date
    Apr 2012
    Posts
    61
    Rep Power
    0

    Default Re: Why would I get a NoClassDefFoundError exception when I didn't change anything?

    Okay so it has just started working again. I tried doing a Println on the first line in the constructor of the offending class (ClientGameFrame) which made the error move to a new class (ClientSock). I did the same to ClientSock in the constructor and voila, it now works. I deleted the 2 Printlns and....it still works ! I really don't understand this, but I guess i know how to fix it if it happens again.

  3. #3
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: Why would I get a NoClassDefFoundError exception when I didn't change anything?

    Not sure what happens in your case, but you should be aware of next situation when compiling.

    Imagine you have two classes A and B.
    Class A instantiate object from class B.

    Imagine that you have compiled them at some point of time and it works ok. You will have next two files A.class and B.class in your classes folder. When you run "java A" it will work and instantiate object from B.

    Now imagine that you changed something in class B and it wont compile again (for some error in code).
    Try to run class A again and you will probably see that it works ok, even if class B wont compile.
    The reason for this is that those previously compiled classes A.class and B.class are still in classes folder (if class B is not compiled it wont overwrite existing B.class).

    This is the point of program misbehavior during testing / compiling and the reason can't be identified easily.

    I think something similar happens in your case, as you said after you successfully compile them again (with this extra code) they start to work without some obviously reason.

    The best solution is to delete previously compiled classes and give fresh start. Most of IDEs have Clean Project command that do exactly that -delete all previously created classes.

    I don't know if I wrote this clear enough but at least keep in mind last part of cleaning old classes.

  4. #4
    Teedo is offline Member
    Join Date
    Apr 2012
    Posts
    61
    Rep Power
    0

    Default Re: Why would I get a NoClassDefFoundError exception when I didn't change anything?

    Thanks for the reply, i should have mentioned that i tried to 'clean and build' with no success. It has happened 2 more times since I posted this thread and I got it working again by the same way of printlns in the constructor.

  5. #5
    milovan is offline Senior Member
    Join Date
    Jan 2011
    Location
    Belgrade, Serbia
    Posts
    301
    Rep Power
    4

    Default Re: Why would I get a NoClassDefFoundError exception when I didn't change anything?

    well, strange...

Similar Threads

  1. Replies: 2
    Last Post: 01-20-2014, 07:45 AM
  2. Replies: 9
    Last Post: 07-16-2012, 03:42 AM
  3. Replies: 3
    Last Post: 06-28-2012, 12:33 PM
  4. Replies: 6
    Last Post: 08-18-2008, 06:44 AM
  5. Replies: 2
    Last Post: 07-13-2008, 05:46 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
  •