可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
This question already has an answer here:
int[][][] inputs; inputs = new int[10][][]; inputs[0] = 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 :-)
回答1:
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};
回答2:
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.
回答3:
The last line should simply be:
inputs[0][0] = {1,1, etc.};