Skip to content Skip to sidebar Skip to footer

Load: Class MyApplet Not Found : Java.lang.ClassNotFoundException. Why Am I Getting This,when The Class File Is There In The Package?

I get the following exception when i try to run the applet : load: class MyApplet not found. java.lang.ClassNotFoundException: MyApplet at sun.plugin2.applet.Applet2ClassLoader.fin

Solution 1:

The archive parameter is resolved relative to the codebase parameter. So in your case the plugin will look for a file MyApplet.class included in a file AppletPackage/JAR.jar.

You should change this to the following:

<applet code="AppletPackage.MyApplet" archive="JAR.jar" height="800" width="800">

This will resolve to AppletPackage/MyApplet.class inside JAR.jar in the same directory as the HTML file.


Solution 2:

This is an attempt to address the error message reported in a comment to my first answer:

java.lang.NoClassDefFoundError: AppletPackage/MyApplet (wrong name: MyApplet)

Looking at the sources, I see that this “wrong name” error message is an indication of a mismatch between file name and class name. You claim that your class is inside AppletPackage, and the file name AppletPackage/MyApplet.class fits that. But the source code you quoted above didn't contain a line

package AppletPackage;

You should add that line, so that the class file contains the fully qualified name of the class. Then you should be able to load it.


Post a Comment for "Load: Class MyApplet Not Found : Java.lang.ClassNotFoundException. Why Am I Getting This,when The Class File Is There In The Package?"