Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

NullPointer Exception when i try to access array..

Posted on 2003-11-30
3
Medium Priority
?
230 Views
Last Modified: 2011-04-14
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..




0
Comment
Question by:gatas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 9846470
YOu have to fill all the array elements too with Cell objects
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 9846494

for (int i=0; i<board.length; i++)
   for (int j=0; j<board[i].length; j++)
      board[i][j] = new Cell();
0
 
LVL 92

Expert Comment

by:objects
ID: 9847156
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question