我正在尝试监听触摸事件并根据触摸事件的类型流对象。但是,只要我触摸屏幕,应用程序就会崩溃。请给我替代方法。
@Override
public boolean onTouchEvent(MotionEvent event) {
final float x = event.getX();
final float y = event.getY();
try {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
stream.writeObject(new Action(x,y,Action.DOWN));
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
stream.writeObject(new Action(x,y,Action.MOVE));
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
stream.writeObject(new Action(x,y,Action.UP));
invalidate();
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return true;
}