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.

[3559 byte] By [FolkFolka] at [2007-11-26 22:47:56]
# 1

When you create an array of X (where X is a reference to some object X)

you haven't created your X objects yet, i.e. all your references still point to

null. here's an example:Object[] array= new Object[5];

Your 'array' holds 5 references to an Object and all references are null.

If you want to make them point to some Object you have to instantiate

the objects:for (int i= 0; i < array.length; i++)

array[i]= new Object();

kind regards,

Jos

JosAHa at 2007-7-10 12:07:12 > top of Java-index,Java Essentials,Java Programming...