小程序上的Java NullPointerException
我正在尝试将一个小程序嵌入到HTML中,以便在我的Uni类中进行演示。每次尝试运行执行小程序时,都会出现一个NullPointerException对话框。我做错了什么小程序上的Java NullPointerException,java,html,eclipse,nullpointerexception,applet,Java,Html,Eclipse,Nullpointerexception,Applet,我正在尝试将一个小程序嵌入到HTML中,以便在我的Uni类中进行演示。每次尝试运行执行小程序时,都会出现一个NullPointerException对话框。我做错了什么 <html> <head> <title> This is my Pacman! </title> <body bgcolor = black text= yellow> <center> <
<html>
<head>
<title> This is my Pacman! </title>
<body bgcolor = black text= yellow>
<center>
<applet code="pacman.InitialClass.class" archive="pacSimq.jar"
width=300 height=350>
</applet>
</center>
<hr>
<a href="https://github.com/awernick/PacSim"> The repository. </a>
</body>
</html>
这就是Java控制台显示给我的错误
java.lang.NullPointerException
at pacman.InitialClass.init(InitialClass.java:34)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.init(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我通过eclipse将其打包到一个jar中,但仍然得到NullPointerException。是什么引起的
Frame frame = (Frame) this.getParent().getParent();
frame.setTitle("Pac-Man"); // line 34
第34行中唯一可能是
null
的是frame
属性。在小程序生命周期的这一点上,小程序显然还没有添加到根框架。发布您的异常、完整调用跟踪及其指向的部分代码。是的,相关代码应该发布在此处,而不是链接中。好的,很好,现在,您需要向我们显示哪一行抛出NPE。@HovercraftFullOfEels我应该在小程序中添加每个类吗?有多个类,它们都很长。@AlanW只要去掉这一行。。。小程序没有标题或调整其大小的选项,这些是桌面应用程序的属性
Frame frame = (Frame) this.getParent().getParent();
frame.setTitle("Pac-Man"); // line 34