-1
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 :-)

2
  • 2
    Did you read the error message? At least in Eclipse it's pretty clear. And even if you don't understand it, you should at least post it in your question! Oct 4, 2011 at 8:54
  • Having tried it, I have to say that the error message from javac is way more cryptic: error: ';' expected. Oct 4, 2011 at 9:51

3 Answers 3

10

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};
5

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.

0

The last line should simply be:

inputs[0][0] = {1,1, etc.};
1
  • 1
    No, that doesn't work. You need the new int[] unless it's an initializer (and this is simply an assignment). Oct 4, 2011 at 8:56

Not the answer you're looking for? Browse other questions tagged or ask your own question.