Error with bracket placement

I am getting this error : Syntax error on token "}", { expected after this token

I am not sure what the problem is here and I've checked that the brackets match, or so I think, so I am not entirely clear of how to fix this problem

 import java.awt.*;


public class Player extends Entity {

    private int directionX, directionY;
    private Main instance;

    private Rectangle hitbox;

    private int life = 3;

    public Player(Main instance, int x, int y){
        super(x , y);
        this.instance = instance;
        width = 16; height = 16;

        hitbox = new Rectangle(x, y, width, height);
    }

    public void draw(Graphics g){
        move();

        g.setColor(Color.WHITE);
        g.fillOval(hitbox.x, hitbox.y, hitbox.width, hitbox.height);
        g.setColor(Color.WHITE);
        g.drawString("Lives: " + life, 20, 20);
    }

    private void move(){
        if(!instance.getStage().isCollided(hitbox)){
            directionY = 1;
        } else { directionY = 0;
        hitbox.x += directionX;
        hitbox.y += directionY;
        }
    } // <<<<<< Getting error here <<<<<<<<<<

    if(instance.getEnemyManager().isCollided(hitbox)){
        if(life > 0){
            life--;
            hitbox.x = 800 / 2 - width / 2;
            y = 390;
        } else {
            instance.setGameOver(true);
        }
        }


    public void setdirectionX(int value){
        directionX = value;
    }

    public void setdirectionY(int value){
        directionY = value;
    }
}

If anyone could answer this question I'd be very happy to know.

Jon Skeet
people
quotationmark

Look at your code in the problematic area:

private void move(){
    if(!instance.getStage().isCollided(hitbox)){
        directionY = 1;
    } else { directionY = 0;
    hitbox.x += directionX;
    hitbox.y += directionY;
    }
}

if(instance.getEnemyManager().isCollided(hitbox)){

The closing brace is the end of the method... and then you've got an if statement which is in the middle of the class declaration, not in any method. Did you intend that to be part of move()? If so, you need to remove the closing brace just before it.

Note that in your post at least, the indentation is all over the place. It really helps if you get your IDE to format your code, so you can see what code is part of what method, etc. It makes it a lot easier for other people to read, too...

people

See more on this question at Stackoverflow