Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Weird problem with static arrays

Thread view: 
m.surion@gmail.com - 01 Feb 2006 22:00 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.