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

    Default error when indexing an array defined as final int

    i receive syntax error: insert "}" to complete the block
    see:
    final int SCALE = 2;
    int [] scale = new int [SCALE];
    scale [0] = 1;

    Java Code:
    package ProjectTest;
    
    public class Stage {
    	int level;
    	int credit;
    
    	final int SCALE = 2;
    	
    	int [] scale = new int [SCALE];
    	scale [0] = 1;
    	
    	public Stage()
    	{
    		this.level = 1;
    		this.credit = 1;
    	}
    	public void setNextStage(int level, int credit)
    	{
    		this.level = level+1;
    		this.credit = credit+1;
    	}
    	public int getCurrentLevel()
    	{
    		return this.level;
    	}
    	public int getCurrentCredit()
    	{
    		return this.scale[this.credit];
    	}
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: error when indexing an array defined as final int

    Your problem is where your code is located. These lines are in the declaration section of your program outside of any method or constructor:

    Java Code:
       int level;
       int credit;
    
       final int SCALE = 2;
        
       int [] scale = new int [SCALE];
       scale [0] = 1;
    All of that code is fine except for the last one. The last line is not a variable declaration or declaration with initialization but rather an assignment without declaration, and this must be called inside of a method, constructor, or some other similar block. For instance, it would make sense to put that last line in your constructor or an initializer block.

  3. #3
    amrmb09 is offline Member
    Join Date
    Nov 2010
    Posts
    75
    Rep Power
    0

    Default Re: error when indexing an array defined as final int

    thanks......
    Regards

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: error when indexing an array defined as final int

    You're quite welcome!

Similar Threads

  1. Indexing an associative array
    By djgovins in forum Lucene
    Replies: 4
    Last Post: 06-06-2011, 09:24 AM
  2. Error - message is already defined in main
    By dimesnnix in forum New To Java
    Replies: 4
    Last Post: 06-01-2011, 10:24 PM
  3. Error: The Type Property Already Defined
    By cest.lavie16 in forum New To Java
    Replies: 2
    Last Post: 04-19-2011, 01:32 AM
  4. Getting error when indexing full wwwroot site
    By cincioh78 in forum Lucene
    Replies: 1
    Last Post: 04-13-2010, 05:15 PM
  5. [SOLVED] indexing an element in an array help!
    By anthonym2121 in forum New To Java
    Replies: 1
    Last Post: 04-03-2009, 06:21 PM

Posting Permissions

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