Expanding 2D array results in Null Pointer Exception, what to do?
in
Programming Questions
•
1 year ago
Hello,
I get a "NullPointerException" running the following code:
int[][] MyArray = new int[5][8];
void setup() {
size(100, 100);
noLoop();
}
void draw() {
MyArray = (int[][]) expand(MyArray);
MyArray[0] = (int[]) expand(MyArray[0]);
println(MyArray.length); // 10 -> expected
println(MyArray[0].length); // 16 -> expected
MyArray [2][5] = 34;
println(MyArray[0] [5]); // 0 -> ??
MyArray [8] [10] =41; // Null Pointer Exception
}
It seems to me I have to instanciate the expanded array. But how to do (without loosing the data of the original array)?
Thanks in advance for any kind of help!
Carlos
I get a "NullPointerException" running the following code:
int[][] MyArray = new int[5][8];
void setup() {
size(100, 100);
noLoop();
}
void draw() {
MyArray = (int[][]) expand(MyArray);
MyArray[0] = (int[]) expand(MyArray[0]);
println(MyArray.length); // 10 -> expected
println(MyArray[0].length); // 16 -> expected
MyArray [2][5] = 34;
println(MyArray[0] [5]); // 0 -> ??
MyArray [8] [10] =41; // Null Pointer Exception
}
It seems to me I have to instanciate the expanded array. But how to do (without loosing the data of the original array)?
Thanks in advance for any kind of help!
Carlos
1