File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes array access problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "array access problem" Watch "array access problem" New topic
Author

array access problem

Tyler Jordan
Ranch Hand

Joined: Nov 17, 2003
Posts: 70
I'm having trouble figuring out why I'm having difficulty with this multidimensional array. It seems to be an accessibility issue since I've tested the declaration and defining of the elements within the array. The issue point is the last line in the code below. For some reason, I get a nullpointerexception whenever I've run the code. It spits out the same error whether or not I hard-code the values. I've verified that isMarked[1][1] is defined and I've hard-code the last array to isMarked[1][1] and I get nullpointerexception.

This is my basic code, the isMarked array is declared in another class:



Thanks,

-Tyler
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32675
    
    4
I shall go into pedantic mode and point out that there is no such thing as a multidimensional array in Java; there are only arrays of arrays.

So you have an array of boolean[] arrays? Suggest you add this sort of thing after the first for loopYou shouldn't get the members of the arrays, but an un-overridden toString() method straight out of the Object class. You are hoping to get a printout like this
[[Z@12345abc
[Z@23456bdc
[Z@34567cde
[Z@45678def
. . . but I think you will get something more like this
[[Z@12345abc
null
null
[Z@45678def
. . . in which case look closely at where you are initialising isMarked. Are you initialising it once or several times? If you initialise it several times, you will lose all its members and only have the last member actually pointing to an object reference. If there is no object reference, you will get an NPE (what we who have been on the Ranch for more than a week call a NullPointerException).

Hint, hint!
Tyler Jordan
Ranch Hand

Joined: Nov 17, 2003
Posts: 70
Yes, thats exactly what it was. The loop was not supposed to keep redefining the container array. I moved the following code above my "for" loop and fixed the nullpointers:



Thanks!
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: array access problem
 
Similar Threads
loading 2D array
Runtime Error - Need Help
Sun Cirtification
Using POI - Connection reset by peer
How do I handle "The Matrix" ?