Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

syntax error: insert } to complete ClassBody

Tags:

java

android

I created a method and keep getting an error that I need to include a } at the end of my method. I put the } in and the error is still there! If I then delete that } the same error will pop up on a prior method; and that error wasn't there before. in other words, if i type the } on my most recent method then the error stays there and only there. if i delete it, it duplicates that error on my prior method.

private void putThreeBeepers() {
for (int i = 0; i < 2; i++) {
    putBeeper();
    move();
}
putBeeper();
}
private void backUp() {
turnAround();
move();
turnAround();
   }
like image 778
LuxuryMode Avatar asked Oct 27 '10 04:10

LuxuryMode


People also ask

What is Classbody in Java?

The class body component of a class implementation can itself contain two different sections: variable declarations and methods. A class's member variables represent a class's state and its methods implement the class's behavior.

What is record expected error in Java?

The <identifier> expected error is a very common Java compile-time error faced by novice programmers and people starting to learn the language. This error typically occurs when an expression statement (as defined in [3]) is written outside of a constructor, method, or an instance initialization block.


1 Answers

You really want to go to the top of your file and do proper and consistent indention all the way to the bottom.

For example...

private void putThreeBeepers() 
{
    for (int i = 0; i < 2; i++) {
        putBeeper();
        move();
    }

    putBeeper();
}

private void backUp() 
{
    turnAround();
    move();
    turnAround();
}

Odds are, somewhere along the line, you are missing a }. Your description isn't super clear, but if the code you posted is how you actually have it formatted in your file then odds are you just missed something somewhere... and poor indentation makes it very hard to spot.

The fact that the message is changing is confusing, but it is the sort of thing you see in these cases.

like image 175
TofuBeer Avatar answered Sep 16 '22 23:09

TofuBeer