• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Multidimentional Array Problem

 
Sheetal Kaul
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic