开发者

syntax error: insert } to complete ClassBody

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 t开发者_StackOverflowhe 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();
   }


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.


the error might be misleading. In my case i had incorrect/incomplete comment statements such as below which is broken lead to this error:

/*
//  */
*/

Fixing the comments fixed the error. Hope this helps. Thanks.


I think this can be caused by a number of different problems. :(

In my case it was that I have forgotten to specify the type of two parameters in one of my methods declareations. To fix I had to change this: onUpgrade(SQLiteDatabase pDb, pOldVersion, pNewVersion) {

} to this: onUpgrade(SQLiteDatabase pDb, int pOldVersion, int pNewVersion)


It might be due to invisible Chars when copying code from PDF ebook. Be careful of the little red dot '.'

Choose 'Select First Character' -> then delete it.

syntax error: insert } to complete ClassBody


Also, the same error might occur if you accidentally write an if-statement outside of a method. I kept overlooking it since I was looking at the bracket-matching only.


I just simply add another"}",makes as "}}",then problem solved

I didnt have to put anther "}" for my other java code exercise.

Im a java beginner,I've come across same problem so I searched online found this thread.Hope this help


Had the same problem. Turned out to be a very fundamental oversight. I was having the properties of a class declared like this:

private Texture foo;
private Sprite bar;
foo = new Texture();
bar = new Sprite();

The mistake was i had been instantiating the foo and bar variables outside the functions of the class. When I put the

foo = new Texture();
bar = new Sprite();

into their proper functions (like below), the error went away.

private Texture foo;
private Sprite bar;
// function
public void instantiateVariables(){
foo = new Texture();
bar = new Sprite();
}


I got this error due to a missing <%.


Here are the steps.

  1. Just copy paste your code in notepad
  2. Remove copy from Java file
  3. Again copy notepad and paste into Java file.
  4. An error will be gone.


This question have already accepted answer but still there are some other problems where it occurs (like even though all statements are there correctly sometimes we will get this issue) and there are solutions too.

Recently I came across like this situation in eclipse workspace.

The solution is

  1. Take the back up of that java file.
  2. Remove the java file from that location and do the build/compile
  3. Paste the file in the same location and do the build/compile
  4. If the above step 3 does not work create new file and paste the content/code from backup file and do the build/compile
  5. If the above step 3&4 both are not working then type the code of that file manually end-to-end and do the build/compile


If this error comes in jsp, look for the braces. if open or close braces are missing, we will get this error.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜