我想将java应用程序转换为applet,但是我在浏览器中加载它时遇到问题我认为这是因为包。
package com.applet;
import java.applet.Applet;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
//import javax.swing.JOptionPane;
@SuppressWarnings("serial")
public class AppletDriver extends Applet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
CleanerPanel cFrame = new CleanerPanel();
add(cFrame);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}
这是我在Eclipse中运行它时用来调用applet的代码。 这是html代码:
<applet archive="app.jar" code="bin/com/applet/AppletDriver.class" width=350 height=200>
</applet>
app.jar是eclipse项目主目录中的任何建议吗?
来自浏览器java控制台的错误:
java.lang.NoClassDefFoundError: bin/com/applet/AppletDriver (wrong name: com/applet/AppletDriver)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
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: bin/com/applet/AppletDriver (wrong name: com/applet/AppletDriver)
答案 0 :(得分:1)
从bin\
属性值的开头删除code
,并使用/
代替\
(我们不再在华盛顿)。如果jar位于名为bin
的目录中,那么您将需要使用archive="bin/app.jar"
。
实际上在查看堆栈跟踪时,jar的构造不正确。类文件应位于com/applet
目录中,而不是bin/com/applet
。