您好我写了这段代码,我不明白为什么要给我syntax error on token "}", delet this token
?
private class DemoView extends View{
public DemoView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}//here***
final int x = 0;
final int y = 0;
this.setOnTouchListener(new View.OnTouchListener(){
public boolean onTouch(View v, MotionEvent e){
switch(e.getAction()){
case MotionEvent.ACTION_DOWN:
x++;
break;
case MotionEvent.ACTION_MOVE: // touch drag with the ball
// move the balls the same as the finger
x = x-25;
y = y-25;
break;
}
return true;
}//here***
}
由于
答案 0 :(得分:2)
多个错误:
setOnTouchListener()
错过了大括号。View.OnTouchListener
以下是更正的代码(我希望它符合您的意图):
public class DemoView extends View {
int x = 0;
int y = 0;
public DemoView(Context context) {
super(context);
this.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
x++;
break;
case MotionEvent.ACTION_MOVE: // touch drag with the ball
// move the balls the same as the finger
x = x - 25;
y = y - 25;
break;
}
return true;
}//here***
});
}
}
答案 1 :(得分:0)
您忘记了文件末尾的一个}
。声明两个字段后的语句也不包含在任何方法中。您应该将它们移动到构造函数。