Results 1 to 5 of 5
- 12-29-2010, 04:18 AM #1
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
[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: mainLast edited by Gordy.Liang; 12-30-2010 at 03:50 AM.
- 12-29-2010, 02:30 PM #2
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Seems like you classes have class and instance initializers:
Note thatJava 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. } }
is basically the same thing.Java Code:class ClassName { static AnotherClass variable0 = new AnotherClass(); //This is probably why your code runs. AnotherClass variable1 = new AnotherClass(); }Ex animo! Hibernate
Java, Arch Linux, C, GPL v3, Bash, Eclipse, Linux VT, GNOME 2 and many buttons on windows.
- 12-30-2010, 03:28 AM #3
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
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...
- 12-30-2010, 03:45 AM #4
Member
- Join Date
- Dec 2010
- Posts
- 10
- Rep Power
- 0
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
- 12-30-2010, 01:23 PM #5
- Join Date
- Dec 2010
- Location
- Stockholm, Sweden
- Posts
- 222
- Blog Entries
- 9
- Rep Power
- 3
Similar Threads
-
class instantiation in referenced project causes ClassNotFoundException
By liorchaga in forum EclipseReplies: 12Last Post: 08-02-2010, 02:39 PM -
ClassNotFoundException
By oontvoo in forum Java AppletsReplies: 7Last Post: 05-13-2010, 11:09 PM -
converting java class file to exe file
By satheeshtech in forum Advanced JavaReplies: 5Last Post: 07-18-2009, 11:47 PM -
ClassNotFoundException
By Chezelle in forum Java AppletsReplies: 5Last Post: 12-24-2008, 04:26 PM -
Able to find class file in WEB-INF/classes but not after add sub folders in class dir
By vitalstrike82 in forum Web FrameworksReplies: 0Last Post: 05-13-2008, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks