0

遇到一些错误,不知道该怎么办。请帮忙。尝试在 android 版本 1.5 中开发蛇游戏并使用 eclipse sdk 版本 4.2.0 似乎这些错误是唯一让我无法调试我的游戏的事情。

The method getX() in the type MotionEvent is not applicable for the arguments (int) 
The method getY() in the type MotionEvent is not applicable for the arguments (int) 
The method getX() in the type MotionEvent is not applicable for the arguments (int) 
The method getY() in the type MotionEvent is not applicable for the arguments (int) 
The method getPointerCount() is undefined for the type MotionEvent  
The method getPointerId(int) is undefined for the type MotionEvent  
ACTION_POINTER_DOWN cannot be resolved or is not a field    
The method getX() in the type MotionEvent is not applicable for the arguments (int) 
The method getY() in the type MotionEvent is not applicable for the arguments (int) 
ACTION_POINTER_UP cannot be resolved or is not a field  MultiTouchHandler.java  
ACTION_MASK cannot be resolved or is not a field    
ACTION_POINTER_ID_MASK cannot be resolved or is not a field 
ACTION_POINTER_ID_SHIFT cannot be resolved or is not a field
The method getPointerId(int) is undefined for the type MotionEvent

编码:

public boolean onTouch(View v, MotionEvent event) {  
    synchronized (this) {  
        int action = event.getAction() & MotionEvent.ACTION_MASK;  
        int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK) >>   MotionEvent.ACTION_POINTER_ID_SHIFT;  
        int pointerId = event.getPointerId(pointerIndex);   

        switch (action) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_POINTER_DOWN:
            touchEvent = touchEventPool.newObject();
            touchEvent.type = TouchEvent.TOUCH_DOWN;
            touchEvent.pointer = pointerId;
            touchEvent.x = touchX[pointerId] = (int) (event
                    .getX(pointerIndex) * scaleX);
            touchEvent.y = touchY[pointerId] = (int) (event
                    .getY(pointerIndex) * scaleY);
            isTouched[pointerId] = true;
            touchEventsBuffer.add(touchEvent);
            break;

        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_POINTER_UP:
        case MotionEvent.ACTION_CANCEL:
            touchEvent = touchEventPool.newObject();
            touchEvent.type = TouchEvent.TOUCH_UP;
            touchEvent.pointer = pointerId;
            touchEvent.x = touchX[pointerId] = (int) (event
                    .getX(pointerIndex) * scaleX);
            touchEvent.y = touchY[pointerId] = (int) (event
                    .getY(pointerIndex) * scaleY);
            isTouched[pointerId] = false;
            touchEventsBuffer.add(touchEvent);
            break;

        case MotionEvent.ACTION_MOVE:
            int pointerCount = event.getPointerCount();
            for (int i = 0; i < pointerCount; i++) {
                pointerIndex = i;
                pointerId = event.getPointerId(pointerIndex);

                touchEvent = touchEventPool.newObject();
                touchEvent.type = TouchEvent.TOUCH_DRAGGED;
                touchEvent.pointer = pointerId;
                touchEvent.x = touchX[pointerId] = (int) (event
                        .getX(pointerIndex) * scaleX);
                touchEvent.y = touchY[pointerId] = (int) (event
                        .getY(pointerIndex) * scaleY);
                touchEventsBuffer.add(touchEvent);
            }
            break;
        }

        return true;
    }
}
4

2 回答 2

0

从外观上看,您的方法/变量与您使用它们的上下文所需的类型不匹配。

查看您的代码,看看方法参数和返回类型是否都匹配。

于 2012-07-04T08:06:06.853 回答
0

您遇到错误的所有这些方法在您选择的 API 级别中均不可用。要么提高 API 级别,要么删除任何特定于多点触控的代码。

于 2012-07-04T08:32:40.343 回答