JButton buttonArray[][] = new JButton [6][7];
JPanel grid;
JButton b1;
grid.setLayout (new GridLayout(6,7,0,0));
slot = new ImageIcon ("gameboard.png");
for (int i = 0; i < 6; ++i)
{
for (int j = 0; j < 7; ++j)
{
b1 = new JButton (slot);
buttonArray[i][j] = b1;
buttonArray[i][j].setContentAreaFilled (false);
buttonArray[i][j].setBorderPainted (false);
grid.add(buttonArray[i][j]);
}
}
I am getting a NullPointerException which points to the grid.setLayout (new GridLayout(6,7,0,0)); part and to the new GameBoard(); which is in the main method at the bottom.
I add grid panel t o another panel as well, together with other panels:
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add("North", panel1);
panel.add("Center",grid);
panel.add("South",panel2);
add(panel);
I did initialize grid and buttonArray[][] already. What am I missing?
grid = new ...somewhere...grid? You haven't shown that. If you're not, then presumably it still has anullvalue...