Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
小程序上的Java NullPointerException_Java_Html_Eclipse_Nullpointerexception_Applet - Fatal编程技术网

小程序上的Java 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中,以便在我的Uni类中进行演示。每次尝试运行执行小程序时,都会出现一个NullPointerException对话框。我做错了什么

<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