Results 1 to 12 of 12
  1. #1
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default noClassDefFoundError

    I am currently making a game and my software is getting pretty big (relativly, 9 classes, about 600 lines of code) and suddenly eclipse stops excecuting my program. When I try to run or debug my program it says there is an error in my code, but nowhere in my code it shows an error. When I run my code anyway, I get this:

    Java Code:
    java.lang.NoClassDefFoundError: tester
    Caused by: java.lang.ClassNotFoundException: tester
    	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"
    It seems to me it can't find the main tester class, which is just:

    Java Code:
    import java.awt.*;
    import java.util.*;
    import javax.swing.*;
    public class tester
    {
    	public static void main(String[] args)
    	{
    		new callEditor();
    	}
    }
    Because when debugging, it never reaches the first line of code ("new callEDitor();"), I gues that isn't the problem. It seems eclipse can't find the tester class itself, which is odd because I haven't changed that class since yesterday and the program ran perfectly yesterday.

    Can anyone point me to the problem?

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

    Default

    Did you define that constructor in the relevant class? My concern is that you've save the file with the same class name?

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    What happens if you open a command prompt, change to the folder with the tester.class file and enter:
    java tester

  4. #4
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    @Eranga: I checked, the class name is the same name as the saved name.

    @Norm: how do I change folders in the command prompt?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Use the cd command: cd dirname
    To go up on level: cd ..
    Use the dir comand to see the contents of the current directory.

    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.

  6. #6
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Thanks for the help, here is the error I got:

    Java Code:
    Exception in thread "main" java.lang.NoClassDefFoundError: tester
    Caused by: java.lang.ClassNotFoundException: tester
            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)
    Could not find the main class: tester.  Program will exit.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    You left off the command that you entered to get the error.
    Is the tester.class file in the current directory?
    Here is what I get when I issue a java command for a missing class file:
    Java Code:
    D:\Testing>java asdfasdfasdf
    Exception in thread "main" java.lang.NoClassDefFoundError: asdfasdfasdf
    Caused by: java.lang.ClassNotFoundException: asdfasdfasdf
            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)
    Could not find the main class: asdfasdfasdf.  Program will exit.
    Make sure there is a tester.class file in the folder before issuing the java command.

  8. #8
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    Well, all my class files are .java files, so there isn't a tester.class file. I do know for certain that there is a tester.java file in that directory.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    all my class files are .java files,
    None of your 'class' files have the .java extension. Class files are the output of the javac compiler. Java files are source files that are compiled to class files.

    There MUST be a .class file for the java command. .java files are NOT used by the java command.
    You create a .class file from a .java file by compiling the .java file.
    Use the javac command to create the .class file.

    The problem is you are using an IDE that has many folders with different contents. Some for .java files and some for .class files and some for other files.
    If you try to bypass the IDE and do steps manually without understanding how the IDE works, you'll have problems.
    Last edited by Norm; 08-21-2010 at 05:39 PM.

  10. #10
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    But the whole problem is that the IDE is giving the error message. The only reason I tried to bypass it manuelly is because you asked me to, and that just gave exactly the same error message.

  11. #11
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Sorry, I don't know how to use your IDE.

    If you go to the folder with the tester.class file and enter:
    java tester
    The java program will start executing the tester class.

    If there is no tester.class file, go to the folder with the tester.java file and enter:
    javac tester.java
    Then do
    java tester

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

Similar Threads

  1. NoClassDefFoundError
    By Dbirge in forum New To Java
    Replies: 0
    Last Post: 03-16-2010, 05:01 PM
  2. help with NoClassDefFoundError
    By chikoyzki06 in forum New To Java
    Replies: 2
    Last Post: 11-25-2009, 11:38 AM
  3. Message NoClassDefFoundError
    By karim in forum Eclipse
    Replies: 1
    Last Post: 03-20-2009, 03:43 PM
  4. Getting NoClassDefFoundError through quicktime API
    By sunil.mact in forum Advanced Java
    Replies: 3
    Last Post: 01-23-2009, 02:59 PM
  5. NoClassDefFoundError
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-18-2008, 12:20 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
  •