尝试运行多个类的小程序时出现 NullPointerException

发布于 2024-08-08 13:43:43 字数 649 浏览 4 评论 0原文

我正在尝试在 html 页面中显示一个小程序。我过去曾成功地做到这一点,但现在我在小程序中有多个类,每次尝试在 html 页面中加载小程序时,我似乎都会收到错误。有一段时间,我手动编写了 html 页面,但后来我意识到 netbeans(我正在使用的 IDE)中的小程序查看器为您创建了一个 html 页面,这与我正在编码的页面相同。

该应用程序在小程序查看器中运行时没有错误,但当我尝试在 html 页面中运行它时,会显示以下消息:

java.lang.NullPointerException
at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(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.NullPointerException

我测试了另一个小型单类小程序,它在相同条件下在 html 页面中运行良好。有什么想法可能是错误的吗?

I'm trying to display an applet in an html page. I've had success doing this in the past, but now that I have more than one class in the applet, I seem to get an error every time I try to load the applet in an html page. For a bit, I was writing the html page by hand, but then I realized the applet viewer in netbeans (the IDE I'm coding in) created an html page for you, which is the same as the one I was coding.

The application runs error-free when in the applet viewer, but the following message is displayed when I try to run it in the html page:

java.lang.NullPointerException
at sun.plugin2.applet.Plugin2Manager.findAppletJDKLevel(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.NullPointerException

I tested another small, one class applet and it ran fine in the html page under the same conditions. Any ideas what may be wrong?

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

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

发布评论

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

评论(2

眼中杀气 2024-08-15 13:43:43

正如杰夫所说,一定要检查小程序的类路径。另请记住,安全权限的工作方式会根据小程序的运行方式而有所不同。与在独立 HTML 页面中运行小程序相比,Eclipse AppletViewer 将使您获得更宽松的权限。

如果您尝试对文件系统进行任何类型的读/写,请确保您的 jar 已签名,以便它可以获得执行其操作所需的权限。一个例子:
http://java.sun.com/developer/onlineTraining/Programming/ JDCBook/signed.html

此外,情况可能已经如此,但请确保您在运行小程序的计算机上安装了实际的 JDK,而不是简单的 JRE。

Definitely check the applet's classpath, as Jeff says. Also keep in mind that the security permissions work differently depending on how the applet is being run. The eclipse AppletViewer will let you get away with more lenient permissions than running the applet in a standalone HTML page.

If you are attempting any sort of read/writes to the file system, ensure that your jar is signed so that it can obtain the permissions necessary to perform its actions. An example:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html

Additionally, this is probably already the case, but ensure you have an actual JDK installed on the machine running the applet, as opposed to simply a JRE.

南冥有猫 2024-08-15 13:43:43

当您在小程序的类路径(存档标签)上缺少所需的 jar 时,我看到了这个神秘的错误消息。您的任何类是否引用了 Eclipse 可能为您解析的其他类,但在您实际运行 applet 时这些类不可用?

I've seen this cryptic error message when you're missing required jars on your applet's classpath (archive tag). Are any of your classes referencing other classes that Eclipse might be resolving for you but that are not available when you actually run your applet?

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