尝试在网页上查看applet时,我收到“找不到类”错误

时间:2011-02-07 23:35:42

标签: java applet package classloader

我在jar文件中存档了许多类。我加载到服务器上的唯一东西是.jar文件。有许多.class文件,但是带有init()方法的文件叫做“Poker.class”我的html如下:

<applet code=Poker
    archive="Poker.jar"
    width=300
    height=300>
</applet>

我尝试用“Poker.class”,Poker.class和“Poker”替换applet代码。当我加载网页时,这些变体在java控制台上给出了略有不同的错误消息,其中差异只是它找不到的类名。错误消息将在下面复制。

我搜索了试图找到答案的网站,但没有任何帮助。如果您有任何见解,我们将非常感激。感谢

Java Plug-in 1.6.0_22
Using JRE version 1.6.0_22-b04 Java HotSpot(TM) Client VM
User home directory = C:\Users\Matt
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
load: class Poker not found.
java.lang.ClassNotFoundException: Poker
    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)
Caused by: java.io.IOException: open HTTP connection failed:https://files.nyu.edu/mbn247/public/Poker.class
    at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
    at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    ... 9 more
Exception: java.lang.ClassNotFoundException: Poker

1 个答案:

答案 0 :(得分:2)

啊,我终于找到了答案。对于那些可能处于同样困境的人:

您必须在代码参数中指定包名称。所以,我的包被称为“扑克”,类是“Poker.class”,我的HTML应该是这样的:

<applet code="poker.Poker.class"
    archive="Poker.jar"
    width=300
    height=300>
</applet>