PDA

View Full Version : problem with JApplet NoClassDefFoundError


sisi
02-15-2010, 05:58 PM
I have been using NetBeans 6.7.1 to develop a JApplet and had an HTML document in the same folder where my Applet.java file was. The HTML page loading this applet had an attribute in the specific APPLET tag which specified the CODEBASE of the corresponding created Applet.class, which used to be ..\..\build\classes. So the whole thing was working like this. However, I recently tried to run the same project but the Applet was not loaded and the following error was given:

java.lang.NoClassDefFoundError: Applet (wrong name: pls/Applet)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.NoClassDefFoundError: Applet (wrong name: pls/Applet)

I must mention that I have checked if the thing was misspelled or smth. but it is correct. However I have noticed that recently the structure of files of the classes stored in NetBeans which used to be build/classes is now changed. I have modified the codebase attribute in the applet correspondingly but still the same problem. I have even placed the HTML in the same folder where the classes are located in NetBeans (in my case build\classes\pls) and removed the CODEBASE attribute but still it presents the same error and it is not working. I am suspecting that it has to do with some updates. Also, the same code works when copied to and compiled with TextPad (of course without the package declaration, but having the same structure of folders as in NetBeans only created on my Desktop). So it has probably smth. to do with NetBeans I think. Therefore, if someone has any idea why this might be happening and how to solve it, please write back. I am waiting forward for your responses. Thank you all beforehand!

cs_student
02-15-2010, 09:34 PM
You say you placed the html page in the directory "build/classes/pls". However, the compiler is saying you are trying to access a class which is in "pls/Applet".

I'm assuming that it's looking for "/build/classes/pls/pls/Applet.class"

Maybe try putting the html file in "/build/classes" or pointing it to look for just "Applet.class"


cs_student

sisi
02-15-2010, 10:16 PM
What I did was move the HTML to build\classes first.
Then I removed the CODEBASE attribute from the applet tag in the HTML and in the CODE attribute that specifies the class I just wrote "pls.Applet.class"
Probably here the package was supposed to be specified as well not only the class. However...Thank You very very very much!