GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Multidimentional Array Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Multidimentional Array Problem" Watch "Multidimentional Array Problem" New topic
Author

Multidimentional Array Problem

Sheetal Kaul
Ranch Hand

Joined: Nov 29, 2004
Posts: 47
Hi,

This program is is not giving any problem at compile time, bt at run time nullPointerException is coming,

please explain

Sheetal

[ May 03, 2005: Message edited by: Sheetal Kaul ]

( tags added for clarity)
[ May 03, 2005: Message edited by: Barry Gaunt ]
Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
Hi Sheetal,

thats pretty obvoius that its gonna throw a NullPointerException as u've defined and constructed a 4d array of size 5(referenced by ref variable str).....u must be knowing this the only condition required to initialize an n-d array so that all the elements are initialized to their default, whatsoever, after contructuion of the topmost array in the n-d array....
but u have also created a 3d array(size is 5).....now null pointer comes because u are trying to assign a value to lowest array in the 5d array which is not created at all(otherwise it will give ArrayIndexOutOfBoundsException)....its just a null(not pionting to anything)
so as a result u get a NullPointerException......and by the way its a Runtime exception which u'll never get at compile time... ;-)

hope its clear..
if not feel free to get back

amit
 
GeeCON Prague 2014
 
subject: Multidimentional Array Problem