javaaide-ide

"Unexpected end of declaration" when dealing with 2D arrays


I have a LibGDX project on my desktop that compiles and runs fine. I imported this project to my phone to use with AIDE-ide and suddenly I have hundreds of errors. I found that any time I use a 2-dimensional array of any sort, the "Unexpected end of declaration" error occurs. This simple example won't compile:

package com.mrhart;

public class SampleClass{
    int[][] sampleArray;
}

I get 4 compilation errors on the line with the 2D-array declaration all claiming "Unexpected end of declaration". As I said before, this is a working project on my desktop, so I'm not really sure what's going on here.

Any help would be appreciated.


Solution

  • Try an initializer block:

    public class sampleClass{
      {
       int [][] sampleArray;
      }
    }
    

    as it seems the array declaration is not quite an instance variable declaration. Which is interesting.

    ref: object-initialization-in-java.html