Results 1 to 4 of 4
  1. #1
    SpaceMonkey is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default "not a statement" error to array declaration

    I'm getting a "not a statement" error pointing at the first square bracket in the following statement:

    int[] final = new int[first.length + second.length];

    ("first" and "second" are other arrays)
    In addition to the "not a statement" error, I'm getting seven other errors pointing at this statement alone, including " ; expected" and "[ expected". However, I think these are a direct result of the first error. Can anyone help me?

    Also, I tested this line using an integer for the length instead of an expression, and it still didn't work.

  2. #2
    adhoc334 is offline Member
    Join Date
    Aug 2010
    Posts
    15
    Rep Power
    0

    Default

    Hey!

    final, in Java, makes a variable a constant.

    for instance, "final int stg = 2;" makes stg always equal to 2, and nothing your program does can modify it (hence the term final/constant).

    change your variable name to something other than final (last, maybe?). that should help. Java doesn't allow you to name variables after modifiers and the like ("int static" doesn't work, for example).


    I also recommend getting an IDE like Eclipse. it will catch these minor mistakes you'll make. extremely useful, even when you're more experienced with programming.
    Last edited by adhoc334; 11-25-2010 at 10:59 PM.

  3. #3
    SpaceMonkey is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    Arrgh, I am a fool! I should have known this! *facepalm* Thanks for the help

  4. #4
    adhoc334 is offline Member
    Join Date
    Aug 2010
    Posts
    15
    Rep Power
    0

    Default

    ha. that won't be your last facepalm, sir. i think i've passed my 50th one by now...

Similar Threads

  1. An "if" statement inside a "for" loop?
    By soccermiles in forum New To Java
    Replies: 18
    Last Post: 04-20-2010, 03:44 AM
  2. Replies: 1
    Last Post: 11-20-2009, 07:58 PM
  3. Simple "if" statement problem....compiling error.
    By CYANiDE in forum New To Java
    Replies: 4
    Last Post: 10-14-2009, 09:56 PM
  4. Replies: 3
    Last Post: 05-25-2009, 08:50 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •