aspose file tools*
The moose likes Beginning Java and the fly likes Array : Multi-dimensional Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array : Multi-dimensional" Watch "Array : Multi-dimensional" New topic
Author

Array : Multi-dimensional

Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
This compiles and runs



This compiles but throws NullPointer exception



Can someone please explain this ?


Regards,<br />Arnab
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18829
    
  40

In the first case, you created an array of int arrays -- and created the int array for each element.

In the second case, you just created an array of int arrays -- but did not create the int array for each element.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Arnb Sen
Ranch Hand

Joined: Feb 23, 2004
Posts: 145
How can you say that "did not create the int array for each element" ? Did not understand.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18829
    
  40

Originally posted by Arnb Sen:
How can you say that "did not create the int array for each element" ? Did not understand.


That is how it works... when you say...



Java will create you an array of int arrays but will not create each element. To do that, you must...



And also notice that each array element does not have to be an int array of the same size.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array : Multi-dimensional