Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Error for a simple array

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Location
    London
    Posts
    15
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Error for a simple array

    I'm trying to create an array that holds 4 values. Declaring the array seems like its not a problem but initialising it keeps giving me this weird syntax error that its expecting "," on token ";", not sure what that means or what its problem is, can anyone help?
    Heres part of the code:

    	JMenuBar menuBar ;
    	JMenu menuSession ;
    	JMenuItem subNewGame, subLoadGame ;
    	MyComponent graphArea ;
    	Color one = Color.blue ;
    	Color two = Color.blue ;
    	Color three = Color.blue ;
    	Color four = Color.blue ;
    	int firstx[]={275,325,325,275} ;
    	int firsty[]={100,100,175,175} ;
    	int secondx[]={150,450,450,150} ;
    	int secondy[]={180,180,230,230} ;
    	int thirdx[]={255,292,180,143} ;
    	int thirdy[]={263,300,412,375} ;
    	int fourthx[]={345,308,420,457} ;
    	int fourthy[]={263,300,412,375} ;
    	int[] strokePos ;
    	strokePos = new int[4] ;
    	Polygon firstStroke = new Polygon(firstx,firsty,4) ;
    	Polygon secondStroke = new Polygon(secondx,secondy,4) ;
    	Polygon thirdStroke = new Polygon(thirdx,thirdy,4) ;
    	Polygon fourthStroke = new Polygon(fourthx,fourthy,4) ;
    	int s1, s2, s3, s4 ;

    The error happens on this line: int[] strokePos ;


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Location
    London
    Posts
    15
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Error for a simple array

    Ok for some reason initialising it when declaring "int[] strokePos = new int[4] ;" doesn't bring up the error... that doesn't make much sense to me, its like the same thing right? Even though I don't have the error anymore, if anyone could tell me what they think the problem could have been I'd be grateful, I'd like to prevent further mistakes like this as much as possible.

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Location
    London
    Posts
    15
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Error for a simple array

    I apologize for this but the error returns when I try to put the value 1 at the first position and I'm getting another error just below that saying I need a semi-colon to complete a statement, but I don't believe I do... Please can someone help me? I will post my code if necessary.

  4. #4
    Junior Member
    Join Date
    Feb 2011
    Location
    London
    Posts
    15
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Error for a simple array

    Sorry for not replying quicker, I have managaed to sort out the problem, but thank you

  5. #5
    Member OutputStream's Avatar
    Join Date
    Apr 2011
    Posts
    32
    My Mood
    Fine
    Thanks
    1
    Thanked 4 Times in 3 Posts

    Default Re: Error for a simple array

    He attempted to initialize a field (strokePos = new int[4] ; ) outside a declaration/method/block :p

Similar Threads

  1. Has to be a simple error, but I can't find it.
    By fride360 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 22nd, 2011, 10:15 AM
  2. logic error somewhere.. working with try & catch, simple array.. please help
    By basketball8533 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 9th, 2010, 12:40 PM
  3. Simple code error
    By robin28 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 7th, 2010, 03:25 PM
  4. Simple error can't figure out.
    By n00bprogrammer in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 30th, 2010, 12:19 PM
  5. Error of data types and type casting in java program
    By chronoz13 in forum What's Wrong With My Code?
    Replies: 8
    Last Post: September 2nd, 2009, 10:22 AM