load: class MyApplet not found : java.lang.ClassNotFoundException. Why am i getting this,when the class file is there in the package?

删除回忆录丶 提交于 2019-12-01 01:52:50

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!