Array error in java [duplicate]
int[][][] inputs;
inputs = new int[10][][];
inputs[0] = 开发者_Python百科new int[1][];
inputs[0][0] = new int[14]{1,1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,1,1};
This is an excerpt from my program, I have no idea why this is causing an error. Isn't this correct?
Thanks in advance :-)
In Eclipse I get a pretty clear error message:
Cannot define dimension expressions when an array initializer is provided.
That means that you can either specify the dimension or the array initializer (i.e. the values). You can't specify both at the same time.
Simply change your last line to
inputs[0][0] = new int[]{1,1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,1,1};
You cannot construct an array with a declared length AND a static initialiser. It must be either one or the other.
change inputs[0][0] = new int[14]{1,1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,1,1};
to inputs[0][0] = new int[]{1,1,-1,-1,-1,1,-1,-1,1,-1,-1,-1,1,1};
- the length of the new array is implicit because you are explicitly initialising the array with 14 elements.
The last line should simply be:
inputs[0][0] = {1,1, etc.};
精彩评论