I am trying to adjust the size of an array using Arrays.copyOf with import java.util.Arrays but for some reason even though the Console is outputting that the array length is 4 like it is supposed to be when i try and assign a value to anything within array row number 4 it is giving me a nullPointerException on the line where it attempts to assign a value to something in row number 4. Can anyone explain this to me?
import java.util.Arrays;
import static java.lang.System.out;
public class Main {
static int TTT[][] = new int[3][3];
public static void main(String[] args) {
TTT = Arrays.copyOf(TTT, 4);
out.print(TTT.length);
TTT[3][0] = 2;
}
}
this gives me an output of:
4Exception in thread "main" java.lang.NullPointerException
at Main.main(Main.java:13)
Does anyone know why this is happen. Also on a side note is there a better way for me too make an array where the size can be changed? If so can you give me some example code please!
out.print(TTT.length);
orSystem.out.print(TTT.length);
? – Lion Jul 9 '12 at 23:51out.print(TTT.length)
is fine because he is importing the specific inner reference. – Jack Jul 9 '12 at 23:54