What is wrong with this code?
From ggc
Question
Ive been working on this code since tuesday and I cant continue because I keep getting errors. I managed to reduce the errors from about 20 to just 1.
Compiler Errors:
ChrisHull/wackadot/Wackadot.java:100: illegal start of expression private void updateScore() ^ 1 error
Here is my code with a few lines above and below the error line:
98 scoreSprite.setLocation(1, 0);
99 }
100 private void updateScore()
101 {
102 scoreSprite.setText("Score: "+score);
103 }
In the instructions it says to add private void updateScore() with no ;
Answer
I can't say for sure without seeing all of the code, but I would bet that you are trying to define a method within another method body.
Count the number of open braces and close braces above line 100. If the braces are properly matched, you should have one more open brace than close brace. If this is the case, post more of your code so I can investigate further.
If instead you find there are two more open braces than close braces above line 100, it means your open and close braces do not match properly and you need to fix them. A great way to do this is to make sure you indent after each open brace and place each close brace directly underneath its matching open brace. An example of how to do this is below.
{
{
{
}
}
{
}
}
Notice above how you can make a clear line of sight from the open brace to its corresponding close brace. This is the goal of indenting after the open braces, allowing you to visually separate blocks of code. This is done in most all programming languages, not just Java.
- This page was last modified on 16 January 2008, at 21:51.
- This page has been accessed 210 times.
- Privacy policy
- About ggc
- Disclaimers
- Powered by MediaWiki!









