我想知道,什麼主要由NullPointerException。主線程中的NullPointerException異常
我對這個錯誤代碼的理解是存在一個使用空值的變量。但它的真正含義是什麼?請尋求你的啓示。
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at TicTacToe.<init>(TicTacToe.java:29)
at TicTacToe.main(TicTacToe.java:49)
public class TicTacToe {
JPanel t3pan;
JButton button1;
JButton button2;
JButton button3;
JButton button4;
JButton button5;
JButton button6;
JButton button7;
JButton button8;
JButton button9;
TicTacToe()
{
t3pan = new JPanel();
GridLayout gl = new GridLayout(3,3);
t3pan.setLayout(gl);
t3pan.add(button1);
t3pan.add(button2);
t3pan.add(button3);
t3pan.add(button4);
t3pan.add(button5);
t3pan.add(button6);
t3pan.add(button7);
t3pan.add(button8);
t3pan.add(button9);
JFrame t3frame = new JFrame();
t3frame.setContentPane(t3pan);
t3frame.pack();
t3frame.setVisible(true);
}
public static void main(String[] args)
{
new TicTacToe();
}
}
沒有看到任何在任何地方初始化的按鈕 – Reimeus 2014-12-27 18:07:54
如果*參數*爲* null *,方法* add拋出NullPointerException *。 [API文檔](http://docs.oracle.com/javase/7/docs/api/java/awt/Container.html#add%28java.awt.Component%29) – sergioFC 2014-12-27 18:10:33
不看API的反對票發佈問題之前的文檔。 – sergioFC 2014-12-27 18:12:53