我在eclipse中构建项目 - swing applet,现在我正试图在浏览器中运行它。
我有3个软件包,假设它们被称为:“pkgApplet”,“pkgFirst”,“pkgSecond”和.class文件。在pkgApplet中,我使用方法main()
的类“main”。无论我做什么,我都无法在浏览器中运行此applet。目前我的HTML代码看起来像这样
<applet code="bin/pkgApplet/main" height="1000" width="1000"/>
无论我如何修改applet标签,浏览器每次都会出现此错误:
NoClassDefFoundError with message bin/pkgApplet/main(wrong name: applet/main)
我尝试使用codebase
属性,将applet打包到.jar文件中并使用archive
属性,但似乎没有任何效果。你知道我做错了什么吗?
答案 0 :(得分:5)
您的小程序格式应为:
<applet codebase="bin" code="pkgApplet.main" height="1000" width="1000"></applet>
bin
是默认目标目录(对于Eclipse),因此需要codebase属性,如上所示。为此,您的HTML
文件需要位于项目目录中。
Java中的注意类以大写开头,而包名称是小写。同样有助于命名描述他们所做事情的类。你可以改为:
<applet codebase="bin" code="pkgapplet.MyMainApplet" height="1000" width="1000"></applet>
您是否意识到您的applet客户端会调用main
中的任何内容?任何启动功能都应该放在init
方法中。