Null pointer exception?
hi. i'm a freshman in college and i need help in my machine problem. every time i try to run my program, it returns a NullPointerException. the compiler says that the problem is in line 18.
this is the class that has the main class
import javax.swing.*;
import java.awt.*;
publicclass MinesweeperMainextends Frame{
publicstaticvoid main(String args[]){
MinesweeperMain MM =new MinesweeperMain();
MinesweeperButtons MB[][] =new MinesweeperButtons[5][5];
Panel gridSize =new Panel();
Panel playArea =new Panel();
Panel mineNumber =new Panel();
//Grid Size
gridSize.add(new Button("5 x 5"));
gridSize.add(new Button("New Game"));
gridSize.add(new Button("10 x 10"));
playArea.setLayout(new GridLayout(5, 5));
for(int i = 0; i < 5; i++){
for(int j = 0; j < 5; j++){
MB[i][j].createButtons();//line 18
}
}
MM.add(gridSize, BorderLayout.NORTH);
MM.add(playArea);
MM.setSize(200, 200);
MM.setVisible(true);
}
}
this is the MinesweeperButtons class:
import java.math.*;
import javax.swing.*;
publicclass MinesweeperButtons{
public MinesweeperButtons(){
this(5, 5);
}
public MinesweeperButtons(int rows,int columns){
MinesweeperButtons MB[][] =new MinesweeperButtons[rows][columns];
}
publicvoid createButtons(){
int bomb = 0;
String strBomb ="";
JButton button;
bomb = (int) (Math.random() * 10) % 3;
strBomb = Integer.toString(bomb);
button =new JButton(strBomb);
}
}
could someone please post the correct code? by the way, this isn't the finished product yet.

