JApplet可以在appletViewer中查看…却不能在HTML中运行…求解……
Java code
package applet;
import javax.swing.*;
public class TEST extends JApplet{
public void init(){
add(new JLabel("Test Applet",JLabel.CENTER));
}
}
HTML code
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
code = "TEST.class"
width = "320"
height = "240"
>
</APPLET>
</CENTER>
</BODY>
</HTML>
运行时的错误提示:Java Plug-in 1.6.0_32
使用 JRE 版本 1.6.0_32-b05 Java HotSpot(TM) Client VM
用户主目录 = C:\Users\hp
----------------------------------------------------
c: 清除控制台窗口
f: 终结在结束队列上的对象
g: 垃圾收集
h: 显示此帮助消息
l: 转储类载入程序列表
m: 打印内存使用
o: 触发日志记录
q: 隐藏控制台
r: 重新载入策略配置
s: 转储系统和部署属性
t: 转储线程列表
v: 转储线程堆栈
x: 清除类载入程序高速缓存
0-5: 设置跟踪级别为<n>
----------------------------------------------------
java.lang.NoClassDefFoundError: TEST (wrong name: applet/TEST)
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 sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.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)
异常:java.lang.
NoClassDefFoundError: TEST (wrong name: applet/TEST)
------解决方案--------------------
html 里 code="applet.TEST.class", 就是说要把包名加上试试。