array problem

int c = 1;int array[][] = new int[3][];array[c][c] = 23;the above code gives a null pointer exception. Why?
[275 byte] By [amitsiemensa] at [2007-10-2 6:58:39]
# 1

I think because you left one of the array boxes empty!!

int[][] myArray = new int[3][put a number here as well];

This means that the code should be something like this:

int c = 1;

int mArray[][] = new int[3][3];

mArray[c][c] = 23;

regards,

sim085

sim085a at 2007-7-16 20:27:42 > top of Java-index,Java Essentials,Java Programming...
# 2

Because, array[1] does not exist, since you have not instantiated it. Try this.

int c = 1;

int array[][] = new int[3][/*some integer equal to or greater than 1 here*/];

array[c][c] = 23;

Drake

Drake_Duna at 2007-7-16 20:27:42 > top of Java-index,Java Essentials,Java Programming...