1

我收到以下异常:

E/AndroidRuntime(31245): java.lang.IllegalArgumentException: pointerIndex out of range
E/AndroidRuntime(31245):        at android.view.MotionEvent.nativeGetAxisValue(Native Method)
E/AndroidRuntime(31245):        at android.view.MotionEvent.getY(MotionEvent.java:1564)
E/AndroidRuntime(31245):        at android.widget.ScrollView.onTouchEvent(ScrollView.java:628)
E/AndroidRuntime(31245):        at android.view.View.dispatchTouchEvent(View.java:4626)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1554)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1320)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
E/AndroidRuntime(31245):        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
E/AndroidRuntime(31245):        at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1862)
E/AndroidRuntime(31245):        at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1286)
E/AndroidRuntime(31245):        at android.app.Activity.dispatchTouchEvent(Activity.java:2315)
E/AndroidRuntime(31245):        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1835)
E/AndroidRuntime(31245):        at android.view.View.dispatchPointerEvent(View.java:4694)
E/AndroidRuntime(31245):        at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2419)
E/AndroidRuntime(31245):        at android.view.ViewRoot.handleMessage(ViewRoot.java:2080)
E/AndroidRuntime(31245):        at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(31245):        at android.os.Looper.loop(Looper.java:132)
E/AndroidRuntime(31245):        at android.app.ActivityThread.main(ActivityThread.java:4126)
E/AndroidRuntime(31245):        at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(31245):        at java.lang.reflect.Method.invoke(Method.java:491)
E/AndroidRuntime(31245):        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
E/AndroidRuntime(31245):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

只需放置 2 个手指并拖动它们一小段距离。应用程序停止并存在。我在下面发布我的代码。这段代码是唯一处理我的视图的 ontouchlistener 的部分。

ScrollView scrollView = (ScrollView) findViewById(R.id.ScrollView11);
        scrollView.setOnTouchListener(textIncreaseListener);
    }

    private OnTouchListener textIncreaseListener = new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            int count = event.getPointerCount();
            if(count == 2){
                Log.d(TAG, "2 pointers");
                return true;
            }
            return false;
        }
    };

有什么帮助吗?

4

1 回答 1

0

问题在于 event.getPointerCount() ,将此行放入 try catch 块或简单地添加一个日志,您就会找到它。你到底想用这个scrollView做什么。

于 2012-09-11T11:37:52.050 回答