File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Multidimentional Array Problem

Sheetal Kaul
Ranch Hand

Joined: Nov 29, 2004
Posts: 47

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

please explain


[ 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) 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

I agree. Here's the link:
subject: Multidimentional Array Problem
It's not a secret anymore!