语法错误,插入“VariableDeclarators”以完成LocalVariableDeclaration

问题描述 投票:3回答:2
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...
    }
}

当我试图调用distanceTraveled时,我收到的错误是:

语法错误,插入“VariableDeclarators”以完成LocalVariableDeclaration

java syntax
2个回答
1
投票

要使语法错误消失并将值分配给distanceTraveledmodify方法public Water update(int time)如下:

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

也许你应该阅读一些关于Java和做一些教程的内容,因为这是非常基本的东西(至少如果我没错你的话)。


0
投票

正确:<%! ...代码...%>(JSP DECLARATION)

错误:<%...代码...%>(JSP SCRIPTLET)

错误:<%= ...代码...%>(JSP EXPRESSION)

例:

<!-- ------------------------------------- -->
<html><body><h1> 
    <%!
    public static String fn(){

        return( "[CORRECT:USE ! MARK]");
    }; 
    %>

    <%= fn() %>
</h1></body></html>
<!-- ------------------------------------- -->

使用“<%”或“<%=”代替“<%!”会得到错误:

org.apache.jasper.JasperException:无法为JSP编译类:

在jsp文件中的第[3]行发生错误:[/index.jsp]语法错误,插入“VariableDeclarators”以完成LocalVariableDeclaration

© www.soinside.com 2019 - 2024. All rights reserved.