Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arrays- Initialising arrays

 
badrinarayanan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting a NullPointerException if i initialise array like this?
I dunno why?
class T1
{
private int[][]a=new int[3][3];
T1()
{
for(int i=0;i<a.length;i++)
{
for(int j=0;j<a[i].length;j++)
{
a[i][j]=0;
}
}
}
}
class T
{
public static void main(String args[])
{
T1 ob1=new T1();

}
}
Any comments please...

Thanks in advance
Badri
 
badrinarayanan
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for troubling you guys...

I got the answer...

If I initialise arrays like this it is taking it properly...

While testing the program in my system I missed the the index variable
in a[i].length...

Sorry once again
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
badrinarayanan,

I'm glad you figured out your problem and that we could serve as your Cardboard Analyst.

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

The proper format is FIRST_NAME + SPACE + LAST_NAME.

Thanks Pardner! Hope to see you 'round the Ranch!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic