Results 1 to 5 of 5
  1. #1
    Gordy.Liang is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Question [Solved] ClassNotFoundException - only for one class file, but others OK

    This is for an old java application I developed long long time ago. A bunch of .class files have been built since then and I am sure they worked very well.

    Now when I re-open this application, it prompts ClassNotFoundException like following (note that I have set CLASSPATH correctly):

    D:\simulation.exe.applet>java Simulation
    Exception in thread "main" java.lang.NoClassDefFoundError: netscape/javascript/J
    SObject
    at Simulation.<init>(Simulation.java:17)
    at Simulation.main(Simulation.java:57)

    Caused by: java.lang.ClassNotFoundException: netscape.javascript.JSObject
    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)
    ... 2 more

    It looks like the problem is that when the constructor call "new simPanel(...)", the class is not found.

    If I try below, it also shows that the class of simPanel can not be found:
    D:\simulation.exe.applet>java simPanel
    Exception in thread "main" java.lang.NoClassDefFoundError: netscape/javascript/J
    SObject
    Caused by: java.lang.ClassNotFoundException: netscape.javascript.JSObject
    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: simPanel. Program will exit.


    But the interesting is that, I have bunch of other classes in the same directory, and if I try to launch those classes, they all can be loaded correctly :confused: (just prompting no main function defined as they are not the main class):

    D:\simulation.exe.applet>java simApplet
    Exception in thread "main" java.lang.NoSuchMethodError: main
    Last edited by Gordy.Liang; 12-30-2010 at 03:50 AM.

  2. #2
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Seems like you classes have class and instance initializers:

    Java Code:
    class ClassName
    {
        static
        {
            //Code that runs as soon as possible when a the class is access for
            //the first the, usually for assigning static variables with values created
            //with multiple instructions.
        }
        
    
        {
            //Code that runs directly after construction.
        }
    }
    Note that
    Java Code:
    class ClassName
    {
        static AnotherClass variable0 = new AnotherClass(); //This is probably why your code runs.
        AnotherClass variable1 = new AnotherClass();
    }
    is basically the same thing.
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

  3. #3
    Gordy.Liang is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Yes it is similar to the codes above.

    Exactly, the code in probmem is:

    Simulation.java
    public class Simulation extends Frame
    {
    ...
    public Simulation()
    {
    ...
    sp=new simPanel(this);
    ...

    static public void main(String args[])
    {
    new Simulation().show();
    }
    ...
    }

    simPanel.java
    public class simPanel extends Panel
    {
    ...
    }


    All the class has been compiled and .class files are there. The problem is that it is prompted that the class file simPanel.class can not be found...

  4. #4
    Gordy.Liang is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Ah yes, I gonna to understand and have resolved the issue now.

    The error message below indicates the class not found for "netscape/javascript/JSObject", but not the class of simPanel. Actually the class simPanel imports JSObject, that why it fails when loading simPanel. I remember that I do have used JSObject if the program runs as an Applet.

    Exception in thread "main" java.lang.NoClassDefFoundError: netscape/javascript/J
    SObject
    at Simulation.<init>(Simulation.java:17)
    at Simulation.main(Simulation.java:57)
    Caused by: java.lang.ClassNotFoundException: netscape.javascript.JSObject
    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)
    ... 2 more


    To resolve the probjem I added following path to CLASSPATH environment variable and it works now.

    C:\Program Files\Java\jre6\lib\plugin.jar

  5. #5
    Hibernate's Avatar
    Hibernate is offline Senior Member
    Join Date
    Dec 2010
    Location
    Stockholm, Sweden
    Posts
    222
    Blog Entries
    9
    Rep Power
    4

    Default

    Quote Originally Posted by lmno920 View Post
    opinion low wow gold Oh it's conscionable goodbye. I buy wow gold short realized that my insomnia cheap wow gold is called paranoia. Concern is so wow power leveling big, I and thousands of fill wow gold succeed every day, I do not fuck their .
    Are you talking about dog food? Why? DO NOT SPAM!
    Ex animo! Hibernate
    Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.

Similar Threads

  1. Replies: 12
    Last Post: 08-02-2010, 02:39 PM
  2. ClassNotFoundException
    By oontvoo in forum Java Applets
    Replies: 7
    Last Post: 05-13-2010, 11:09 PM
  3. converting java class file to exe file
    By satheeshtech in forum Advanced Java
    Replies: 5
    Last Post: 07-18-2009, 11:47 PM
  4. ClassNotFoundException
    By Chezelle in forum Java Applets
    Replies: 5
    Last Post: 12-24-2008, 04:26 PM
  5. Replies: 0
    Last Post: 05-13-2008, 06:16 AM

Posting Permissions

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