JApplet 中未找到类异常

发布于 2024-09-01 00:57:18 字数 1260 浏览 0 评论 0原文

我使用 JApplet 创建了一个简单的 Applet,一切似乎都工作正常,但是当我在小程序中创建名为 ChatUser 的用户定义类的对象时,我收到此错误:-

SEVERE: java.lang.ClassNotFoundException: applet.ChatUser
        at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:713)
        at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:626)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at misc.ChatClient.run(ChatClient.java:43)

知道什么可能是错误的吗?仅当我创建任何用户定义类的对象时才会发生这种情况。我需要设置一些安全设置什么的吗?请帮忙:(

I created a simple Applet using JApplet and everything seems to work fine but as soon i create an object of my userdefined class named ChatUser in my applet, i get this error :-

SEVERE: java.lang.ClassNotFoundException: applet.ChatUser
        at com.sun.enterprise.loader.ASURLClassLoader.findClassData(ASURLClassLoader.java:713)
        at com.sun.enterprise.loader.ASURLClassLoader.findClass(ASURLClassLoader.java:626)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:604)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
        at misc.ChatClient.run(ChatClient.java:43)

Any idea what can be wrong? It only happens when i create an object of any user defined class. Do i need to set some security settings or something? Please help :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尹雨沫 2024-09-08 00:57:18

这只是意味着小程序的运行时类路径中缺少提到的类。

您是否意识到小程序运行在与 Web 服务器运行的环境(即客户端计算机)完全不同的环境中?客户端需要先下载所需的库。该类应包含在小程序的主 JAR 文件中或小程序的 archive 参数中引用的任何库中。您可以指定多个 JAR,并以逗号分隔。

<param name="archive" value="applet.jar,library1.jar,library2.jar">

这会指示客户端在运行小程序之前下载哪些 JAR。

It just means that the mentioned class is missing in the runtime classpath of the applet.

You do realize that applets runs at a completely different environment than where the webserver runs, namely the client machine? The client would need to download the needed libraries first. That class should be included in the applet's main JAR file or in any of the libraries referenced in the applet's archive parameter. You can specify multiple JAR's commaseparated.

<param name="archive" value="applet.jar,library1.jar,library2.jar">

This instructs the client which JAR's to download before running the applet.

残龙傲雪 2024-09-08 00:57:18

启动小程序的方式看起来像是类路径问题。

如果您使用 NetBeans Run 文件启动 applet,Netbeans 可能会将您的项目类路径作为 Applet 的类路径,而不是您在 Applet 的 HTML 页面中指定的类路径。
正如您所看到的,类加载器是 com.sun.enterprise.loader.ASURLClassLoader,它不是 Applet 使用的标准类加载器 (URLClassLoader)。
使用浏览器或 appletviewer 或 jnlp (Java webstart) 运行您的 applet。

It looks like a classpath problem the way you're starting the applet.

If you start the applet using NetBeans Run file, Netbeans probably takes your project classpath as classpath for the Applet and not what you've specified in the HTML page of the Applet.
As you can see the classloader is com.sun.enterprise.loader.ASURLClassLoader which is not the standard classloader (URLClassLoader) that Applets use.
Run your applet using the browser or the appletviewer or jnlp (Java webstart).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文