2
我一直在得到這些錯誤,我無法弄清楚原因。我知道它與按鈕有關,但我不知道如何解決它們。Java中的線程「AWT-EventQueue-0」幫助中的異常
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1090)
at java.awt.Container.add(Container.java:410)
at LightsChasingSolver.<init>(LightsChasingSolver.java:45)
at LightsChasingUI$2.actionPerformed(LightsChasingUI.java:153)
這裏是我的代碼
final JFrame frame2 = new JFrame("Lights Chasing Solver");
GridLayout gridLay = new GridLayout(2,1);
GridLayout grid = new GridLayout(5,5);
JPanel mainPanel = new JPanel(grid);
JPanel legendPanel = new JPanel();
final JButton[][] sht = new JButton[5][5];
for(i=0;i<5;i++){
for(j=0;j<5; j++) mainPanel.add(sht[i][j]);
}
哦。所以這就是問題所在。完全工作。謝謝。哦原諒我的變數名稱,我有點沮喪 – 2013-03-17 16:19:50