我在课本上抄写了一段代码,运行后出现了
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JPopupMenu.add(Unknown Source)
at javax.swing.JMenu.add(Unknown Source)
at SnakeFrame.init(SnakeGame.java:345)
at SnakeFrame.<init>(SnakeGame.java:257)
at SnakeGame.main(SnakeGame.java:21)
错误,大侠帮我看看怎么解决啊,急急急,小弟感激不尽。
main函数中出现NullPointerException(空指针)错误,
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JPopupMenu.add(Unknown Source)
at javax.swing.JMenu.add(Unknown Source)
at SnakeFrame.init(SnakeGame.java:345)
at SnakeFrame.<init>(SnakeGame.java:257)
at SnakeGame.main(SnakeGame.java:21)
这个at后面的是地址,at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JPopupMenu.add(Unknown Source)
at javax.swing.JMenu.add(Unknown Source)这几个是找不到资源,可能是引用错误。
at SnakeFrame.init(SnakeGame.java:345)
at SnakeFrame.<init>(SnakeGame.java:257)
at SnakeGame.main(SnakeGame.java:21)
这三个你可以点进去看看,然后找到问题所在,想数组越界等。
能发下你抄的是什么代码吗,这个错误很广泛