When trying to declare a static array in my program I receive a static forward reference error, i'm not sure what I am doing wrong here...
static Square fieldGrid [ ] [ ] = new Square [ ROWSIZE ] [ COLSIZE ];
this is what I am using.
When trying to declare a static array in my program I receive a static forward reference error, i'm not sure what I am doing wrong here...
static Square fieldGrid [ ] [ ] = new Square [ ROWSIZE ] [ COLSIZE ];
this is what I am using.
The preferred syntax is:
static Square[][] fieldGrid = new Square [ ROWSIZE ] [ COLSIZE ];
Also, have you declared and initialized ROWSIZE
and COLSIZE
by the time you make this declaration?
Are rowsize and colsize declared and initialised before this line? Since they're static, I think order of declaration does matter.
I'm guessing ROWSIZE and COLSIZE are static final ints and they are being declared after you declare the array. Change the order (first declare and initalize ROWSIZE and COLSIZE) and then use them.
Your ROWSIZE and COLSIZE fields need to be initialized before they are used to create your Square array. The Java Language Spec indicates why this restriction is in place:
These restrictions are designed to catch, at compile time, circular or otherwise malformed initializations.