java applet不起作用

时间:2010-05-08 14:49:18

标签: java applet appletviewer

这是家庭作业,但问题不在于编码。我们的任务是编写一个java applet来处理m-grid服务器。我让服务器在apache上运行。它有一些.jar和.class形式的示例applet。 .class版本工作; .jar版本适用于appletviewer,但如果我将它们作为作业提交给服务器,它们会破坏:

load: class examples/pixelcount/PixelCount.class not found.
java.lang.ClassNotFoundException: examples.pixelcount.PixelCount.class
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)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
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)
... 7 more
Exception: java.lang.ClassNotFoundException: examples.pixelcount.PixelCount.class

我不确定这里的问题究竟在哪里,因为它们适用于appletviewer。任何帮助将不胜感激..

编辑:

不知道我是否写得清楚。通过“.class version”我用这个内容引用html文件:

<applet height="300" width="450" code="examples/pixelcount/PixelCount.class"></applet>
带有此内容的

和“.jar”:

<applet height="300" width="450" archive="PixelCount.jar" code="examples.pixelcount.PixelCount.class"></applet>

EDIT2:

可以找到提到的示例jar文件here

3 个答案:

答案 0 :(得分:0)

我认为PixelCount类没有打包在你的jar中。

由于错误是Caused by: java.net.ConnectException: Connection refused: connect,可能是因为它试图从某个地方的网络中获取该类,并且位置不匹配或者代理介于其间。

修改

你确实有m-server的存档,无论可能是什么,都可以找到它?请参阅Java Applet Tag ref. docs。你可能需要像

这样的东西
CODEBASE = codebaseURL
This OPTIONAL attribute specifies the base URL of the applet--the directory 
that contains the applet's code. If this attribute is not specified, then the 
document's URL is used.

CODE是相对于包含applet标记的文档的基本URL。如果要覆盖它,则可能需要该CODEBASE参数。

答案 1 :(得分:0)

它无法找到文件PixelCount.class,它不在目录examples / pixlecount中,这就是为什么会发生此错误。

答案 2 :(得分:-2)

不要在代码属性中包含.class扩展名。

examples.pixelcount.PixelCount 的名称。
examples.pixelcount.PixelCount.class是包含该类的 文件 的名称。

代码属性应为

code="examples.pixelcount.PixelCount"