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
要使语法错误消失并将值分配给distanceTraveled
modify方法public Water update(int time)
如下:
public Water update(int time) {
graphic.draw();
distanceTraveled = 1; // assign a value before returning
return Water.this;
}
也许你应该阅读一些关于Java和做一些教程的内容,因为这是非常基本的东西(至少如果我没错你的话)。
正确:<%! ...代码...%>(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