Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration occurs

Tags:

java

syntax

public class Water {
    private Graphic graphic;
    private float speed;
    private float distanceTraveled;

    public Water(float x, float y, float direction) 
    {
        speed = 0.7f;

        graphic = new Graphic();
        graphic.setType("WATER");   

        graphic.setX(x);
        graphic.setY(y);

        direction = graphic.getDirection(); //direction from Hero as water is fired
    }
    public Water update(int time) 
    {
        graphic.draw();
        return Water.this;
        distanceTraveled; // this is where the error occured...
    }
}

When I tried to call distanceTraveled, I am getting the error as:

Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration

like image 869
Mike Avatar asked Feb 17 '26 09:02

Mike


1 Answers

To make the Syntax error disappear and to assign a value to distanceTraveledmodify the method public Water update(int time) as follows:

public Water update(int time) {
    graphic.draw();
    distanceTraveled = 1; // assign a value before returning
    return Water.this;
}

Maybe you should read a bit about Java and doing some tutorials, because this is very basic stuff (at least if I'm not getting you wrong).

like image 163
mnille Avatar answered Feb 18 '26 22:02

mnille



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!