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

1 に答える 1

0

最初のエラーを読む:

The method getX() in the type MotionEvent is not applicable for the arguments (int) 

これは、MotionEvent の getX() は引数として int を使用して呼び出すことができない、つまり getX(1) ことを示しています。

あなたのコードで私は見ることができます:

touchEvent.x = touchX[pointerId] = (int) (event.getX(pointerIndex) * scaleX);

getX(pointerIndex) を呼び出していることがわかる場合。これはコンパイル エラーです。

他のエラーを読んでコードを見ると、それらをすべて見つけることができるはずです。

私のアドバイス: IDE を入手してください ( Android アプリにはどの Eclipse バージョンを使用する必要がありますか? を参照してください)。これらの問題はすべて赤で強調表示されます。

于 2012-07-04T07:32:53.923 に答える