Link to home
Start Free TrialLog in
Avatar of gatas
gatas

asked on

NullPointer Exception when i try to access array..

Hi there...
I ve got the following class where the array is initialized in the class' constructor..

public class Board {
  public Cell board[][] ;
  Board(int x)
  {
board=new Cell[x][x] ;
  }
Is the above correct?

When i try to access the board array after i declare a Board object
for example: a.board[0][1].someMethod()

I get java.lang.NullPointerException..

I am a java newb so any help would be appreciated..




Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

YOu have to fill all the array elements too with Cell objects
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial