可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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
回答1:
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
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.
回答2:
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.
回答3:
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)
回答4:
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.

回答5:
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.
回答6:
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
回答7:
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(); }
回答8:
I got this error due to a missing .
回答9:
Here are the steps.
- Just copy paste your code in notepad
- Remove copy from Java file
- Again copy notepad and paste into Java file.
- An error will be gone.