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 is defined and I've hard-code the last array to isMarked and I get nullpointerexception.
This is my basic code, the isMarked array is declared in another class:
Joined: Oct 13, 2005
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).
Joined: Nov 17, 2003
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: