File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Arrays- Initialising arrays" Watch "Arrays- Initialising arrays" New topic
Author

Arrays- Initialising arrays

badrinarayanan
Greenhorn

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];
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


Thanks and Regards,<br />Badri
badrinarayanan
Greenhorn

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
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
Don't get me started about those stupid light bulbs.
 
subject: Arrays- Initialising arrays