It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Arrays- Initialising arrays Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays- Initialising arrays" Watch "Arrays- Initialising arrays" New topic

Arrays- Initialising arrays


Joined: Jun 02, 2004
Posts: 9
I am getting a NullPointerException if i initialise array like this?
I dunno why?
class T1
private int[][]a=new int[3][3];
for(int i=0;i<a.length;i++)
for(int j=0;j<a[i].length;j++)
class T
public static void main(String args[])
T1 ob1=new T1();

Any comments please...

Thanks in advance

Thanks and Regards,<br />Badri

Joined: Jun 02, 2004
Posts: 9
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

Joined: Dec 10, 2001
Posts: 7023

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!

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Arrays- Initialising arrays
Similar Threads
multi dimensional arrays
Arrays of Arrays
Multidimensional Arrays
Need explanation about three dimensional arrays
question from kathy/bates book