- The statement
var a = new Array(new Array(4), new Array(4));
is creating a Java array with two elements, one a Java array with 4 elements, and the other a Java Array with 4 elements. Those two should have indexes 0 and 1, so when you reach 2, it fails, exactly like it's supposed to. Since it's Java, and not JS, it won't automagically tack on new elements for you.
- I would look up how Java does multi-dimensional arrays and use that. ArrayList of ArrayList comes to mind, for a fully dynamic jagged array that would work for smaller amounts of data.
Hope this helps...