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
答案 0 :(得分:1)
要使语法错误消失并为distanceTraveled
分配值,请按如下方式修改方法public Water update(int time)
:
public Water update(int time) {
graphic.draw();
distanceTraveled = 1; // assign a value before returning
return Water.this;
}
也许你应该阅读一些关于Java和做一些教程的内容,因为这是非常基本的东西(至少如果我没有弄错你的话)。
答案 1 :(得分:0)
正确:<%! ...代码...%> (JSP声明)
错误:<%...代码...%> (JSP脚本)
错误:<%= ...代码...%> (JSP表达)
示例:
<!-- ------------------------------------- -->
<html><body><h1>
<%!
public static String fn(){
return( "[CORRECT:USE ! MARK]");
};
%>
<%= fn() %>
</h1></body></html>
<!-- ------------------------------------- -->
使用“ <%” 或“ <%=” 代替“ <%!” 会出现错误:
org.apache.jasper.JasperException:无法为JSP编译类:
jsp文件[/index.jsp]中的行[3]发生错误:语法 错误,请插入“ VariableDeclarators”以完成 LocalVariableDeclaration