I'm having errors with static arrays, errors which seem very weird to
me, here is the code which is causing the problem and the error
message. Is it my programming mistake, or is it some problem with
compiler or something?
static int[] wagi = new int[8]; //-line 10
wagi[4]=33; //-line 11
']' expected //-both
errors show error at line 11
<identifier> expected
Andrey Kuznetsov - 01 Feb 2006 22:02 GMT
> static int[] wagi = new int[8]; //-line 10
static {
> wagi[4]=33; //-line 11
}

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Eric Sosman - 01 Feb 2006 22:08 GMT
m.surion@gmail.com wrote On 02/01/06 17:00,:
> I'm having errors with static arrays, errors which seem very weird to
> me, here is the code which is causing the problem and the error
[quoted text clipped - 7 lines]
> errors show error at line 11
> <identifier> expected
Executable statements like `wagi[4]=33;' must
appear inside methods or constructors or initializer
blocks. You can't just drop them amid the field
declarations.
static int[] wagi = new int[8];
{
wagi[4] = 33;
}

Signature
Eric.Sosman@sun.com
Thomas Hawtin - 01 Feb 2006 22:52 GMT
> Executable statements like `wagi[4]=33;' must
> appear inside methods or constructors or initializer
[quoted text clipped - 5 lines]
> wagi[4] = 33;
> }
I assume what was meant was:
static int[] wagi = new int[8];
static {
wagi[4] = 33;
}
The top code has an instance initialise initialising a static instance,
which is probably a mistake (certainly sounds like one).
Tom Hawtin

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
jvc2010@gmail.com - 01 Feb 2006 23:31 GMT
Or you could do:
static int[] wagi = new int[] { 0,0,0,0,33,0,0,0 };
jvc
Roedy Green - 01 Feb 2006 22:13 GMT
>static int[] wagi = new int[8]; //-line 10
>wagi[4]=33;
You did not show the context, but you must declare statics OUTSIDE
methods but INSIDE classes.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.