Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration occurs

39,892

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).

Share:
39,892
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years
    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

  • springcloudlearner
    springcloudlearner over 6 years
    same issue but different scenario, can anyone please help :- public class InterfaceInsideClass { public static void main(String[] args) { ClassO.inner.i; // Error occurs here } } class ClassO { interface inner { int i=10; } }
  • mnille
    mnille about 6 years
    @bharatbhushan: I think here you have multiply issues. First you have an interface which you cannot use for an assignment directly. You should have a class which implements the interface. Member variables in interfaces are final, so even you could use an interface for an assignment you were not allowed to change the value of i.