Results 1 to 13 of 13
  1. #1
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default I get an error code in line 2 '(' expected near 'static'

    Trying to make a checked board display
    Do I not have to put static?! I am new to java
    Comments and help is appreciated :)


    function
    private static int Nrows = 8;
    private static int Ncolumns = 8;

    public void run()
    int sqSize = getHeight()/ Nrows
    for (int i = 0; 1 > Nrows; i++) {
    for (int j = 0; 1 > Ncolumns; j++) {
    int x = j * sqSize;
    int y = i * sqSize;
    Grect sq = new Grect(x, y, sqSize, sqSize);
    sq.setFilled (((i + j) \ 2 !=0);
    add (sq);
    }
    }
    }

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: I get an error code in line 2 '(' expected near 'static'

    function
    What is that supposed to mean? It is not Java.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default Re: I get an error code in line 2 '(' expected near 'static'

    I took out the function. Now it says '=' expected near 'static'

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

    Default Re: I get an error code in line 2 '(' expected near 'static'

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default Re: I get an error code in line 2 '(' expected near 'static'

    I assume you meant no spaces. Now at line 5
    '=' expected at sqSize

    Nrows=8;
    Ncolumns=8;

    public ()
    int sqSize=getHeight()/Nrows
    for (int i=0;1>Nrows;i++) {
    for (int j=0;1>Ncolumns;j++) {
    int x=j*sqSize;
    int y=i*sqSize;
    Grect sq=new Grect(x,y,sqSize,sqSize);
    sq.setFilled (((i+j)/2 !=0);
    add (sq);
    }
    }
    }

  6. #6
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default Re: I get an error code in line 2 '(' expected near 'static'

    I fixed the error at line 5, new code. I like that at least it tells me what line is wrong
    Now thou '<name>' expected near '('

    Nrows=8;
    Ncolumns=8;

    public ()
    sqSize=getHeight()/Nrows
    for (int i=0;1>Nrows;i++) {
    for (int j=0;1>Ncolumns;j++) {
    int x=j*sqSize;
    int y=i*sqSize;
    Grect sq=new Grect(x,y,sqSize,sqSize);
    sq.setFilled (((i+j)/2 !=0);
    add (sq);
    }
    }
    }

  7. #7
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default Re: I get an error code in line 2 '(' expected near 'static'

    At line 6, sorry

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: I get an error code in line 2 '(' expected near 'static'

    Good lord, read Darryl's links and post all of your code. Ask specific questions. I don't have a crystal ball telling me what you want to know.
    I don't even know if your code is Java code.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default Re: I get an error code in line 2 '(' expected near 'static'

    Very discouraging. What makes it not seem java? If I wasn't so determined I might give up. I will eventually figure it out.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,945
    Rep Power
    19

    Default Re: I get an error code in line 2 '(' expected near 'static'

    Darryl's links show you what's expected when you ask a question here.
    This includes the link to BBCode showing how to post code.
    That involves wrapping it in [code] tags [/code] otherwise it is unformatted mush.

    Since you are getting compilation errors then the usual way to post that would be to post the class having the compilation problem and the full text of the problem.

    Since the code you have posted is wildly wrong (hence PhHein's post questioning whether it is Java) I suggest you read the basics of the Java tutorial.
    Getting Started.
    Learning the Java Language.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: I get an error code in line 2 '(' expected near 'static'

    Well, for a start


    1. No class definition
    2. No main entry point
    3. No type definition on Nrow and Ncolumns
    4. The construct "public()" is meaningless in Java
    5. Mismatched curly braces
    6. Unknown Grect method (or perhaps "function")


    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,192
    Rep Power
    19

    Default Re: I get an error code in line 2 '(' expected near 'static'

    Quote Originally Posted by Nrw008 View Post
    Very discouraging.
    And you don't think it's discouraging for us that you don't bother to click on links posted for your betterment?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  13. #13
    Nrw008 is offline Member
    Join Date
    Mar 2013
    Location
    Bellingham,Washington
    Posts
    7
    Rep Power
    0

    Default Re: I get an error code in line 2 '(' expected near 'static'

    I did click on links. Obviously I need to go over basics again. Sorry for wasting people's time.

Similar Threads

  1. Error: { Expected in my code
    By Mattiscool in forum New To Java
    Replies: 4
    Last Post: 10-23-2012, 06:22 PM
  2. error: '{"expected in 10 line
    By lalitha in forum New To Java
    Replies: 1
    Last Post: 10-10-2012, 04:48 PM
  3. Replies: 9
    Last Post: 06-10-2011, 12:40 AM
  4. Replies: 9
    Last Post: 11-22-2008, 11:03 PM
  5. Replies: 1
    Last Post: 08-01-2007, 09:25 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
  •