Results 1 to 9 of 9
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default NoClassDefFoundError

    I have just added this code (and similar code which follows in other methods), but cannot run my program any more (was running fine beforehand). From what I am reading, java doesn't understand what an AtoCSeat class is, even though it was using it multiple time before I added this code, why is it doing this?


    Code added:

    Java Code:
    public static AtoCSeat AtoCSeatSearch(){
            if (seatsAvailible == 0){
                System.out.println("I am sorry, there are no seats availible here. Please try again.");
                addBooking();
            }
            else{
                
            int index = 0;
            
            while (index < A.length){
                if(A[index].isBooked == true ){
                    index ++;              
                }
                else {
                    return A[index];
                }
            }
            
            index = 0;
            
            while (index < B.length){
                if(B[index].isBooked == true ){
                    index ++;              
                }
                else {
                    return B[index];
                }
            }
            
            index = 0;
            
            while (index < C.length){
                if(C[index].isBooked == true ){
                    index ++;              
                }
                else {
                    return C[index];
                }
            }
            }
            AtoCSeat dummy = new AtoCSeat();
            return dummy;                                                           // although never reached, a return value is needed at the end of the method
        }

    Error:
    java.lang.NoClassDefFoundError: AtoCSeat
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.ja va:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(Launcher Helper.java:492)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:484)
    Caused by: java.lang.ClassNotFoundException: AtoCSeat
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    ... 6 more
    Exception in thread "main" Java Result: 1

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,834
    Rep Power
    8

    Default Re: NoClassDefFoundError

    What is the package structure of your classes? What is the file hierarchy?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default Re: NoClassDefFoundError

    I have no idea what that means, sorry.

    This is what the navigation pane looks like for my program, does this help?

    NoClassDefFoundError-j9i0n17.png

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

    Default Re: NoClassDefFoundError

    Throw away the (old) class files and recompile; you're trying to run inconsistent class files.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default Re: NoClassDefFoundError

    I used windows explorer to open up my project and didn't find any class files except for a BookingsSystem.class file in TheatreBookingsSystemPrototype\build\classes

    As you didn't seem to think there was a problem with my code, I ran Clean & Build and then ran the program. To my delight it started working again. I noticed that AtoSeat.class etc also appeared in that directory.

    Was this what you wanted me to do? I was pretty much just clicking things randomly :P
    Could you explain what I actually did?

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

    Default Re: NoClassDefFoundError

    You must've forgotten to rebuild all your class files the first time. One (new) class file assumed there was a method in another (old) class file while there wasn't. The error you saw was a runtime error, not a compile error.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default Re: NoClassDefFoundError

    I didn't forget, I didn't know I ever had to do anything like that.

    So I should periodically rebuild the project using that button I pressed?

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

    Default Re: NoClassDefFoundError

    I don't know which IDE you're using; I use Eclipse and it keeps my projects consistent. Doing a complete rebuild never harms.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    226
    Rep Power
    2

    Default Re: NoClassDefFoundError

    I use NetBeans.
    Thanks for the advice.

Similar Threads

  1. Another NoClassDefFoundError
    By egran001 in forum Eclipse
    Replies: 2
    Last Post: 04-01-2012, 09:42 PM
  2. NoClassDefFoundError
    By PeDz in forum JCreator
    Replies: 17
    Last Post: 02-06-2012, 12:42 AM
  3. NoClassDefFoundError
    By PeDz in forum New To Java
    Replies: 10
    Last Post: 02-05-2012, 06:14 PM
  4. NoClassDefFoundError
    By PeDz in forum Advanced Java
    Replies: 1
    Last Post: 02-04-2012, 02:44 PM
  5. NoClassDefFoundError
    By Josisco in forum JDBC
    Replies: 2
    Last Post: 10-30-2010, 08:07 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
  •