# Solved: Java - Illegal start of expression



## Robincognito (Jun 13, 2010)

I've just started to learn a bit of Java through Greenfoot (a system that teaches Java langauge through games and simulation) but I've just written some code and when compiling, I get an "illegal start of expression" error. I can't see what's wrong with it, because even when I compare the line with another scenario that does work, it looks the same. Any help would be greatly appreciated.

Here is the code in question. I've included the section before the error. The line with the problem is "public void checkKeypress()"

/**
* Switch between Image1 and Image2.
*/
public void switchImage()
{
if (counter == 3)
{
if ( getImage() == image1 )
{
setImage(image2);
}
else
{
setImage(image1);
}
}

/**
* Turn 4 degrees to the left of right depending on the cursor key pressed.
*/
public void checkKeypress() <------------- here
{
if ( Greenfoot.isKeyDown("left") )
{
turn(-4);
}
if ( Greenfoot.isKeyDown("right") )
{
turn(4);
}
if ( Greenfoot.isKeyDown("up") )
{
move();
counter = counter + 1;
}
}


I've literally just started Java (yesterday) so I'm sorry if I've done something obviously stupid. I appreciate any help.


----------



## Robincognito (Jun 13, 2010)

Just realised I was missing a curly bracket. Sorry.


----------

