0

当我多连接我的自定义视图时,我遇到了崩溃:

11-12 21:54:23.048: W/System.err(9625): java.lang.ArrayIndexOutOfBoundsException
11-12 21:54:23.048: W/System.err(9625):     at android.view.MotionEvent.getX(MotionEvent.java:972)
11-12 21:54:23.048: W/System.err(9625):     at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
11-12 21:54:23.048: W/System.err(9625):     at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
11-12 21:54:23.048: W/System.err(9625):     at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
11-12 21:54:23.048: W/System.err(9625):     at com.ex.app.views.PulledItem.determineDrag(PulledItem.java:399)
11-12 21:54:23.048: W/System.err(9625):     at com.ex.app.views.PulledItem.onInterceptTouchEvent(PulledItem.java:290)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:960)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1820)
11-12 21:54:23.048: W/System.err(9625):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1176)
11-12 21:54:23.058: W/System.err(9625):     at android.app.Activity.dispatchTouchEvent(Activity.java:2198)
11-12 21:54:23.058: W/System.err(9625):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1795)
11-12 21:54:23.058: W/System.err(9625):     at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2336)
11-12 21:54:23.058: W/System.err(9625):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1976)
11-12 21:54:23.058: W/System.err(9625):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 21:54:23.058: W/System.err(9625):     at android.os.Looper.loop(Looper.java:150)
11-12 21:54:23.058: W/System.err(9625):     at android.app.ActivityThread.main(ActivityThread.java:4277)
11-12 21:54:23.058: W/System.err(9625):     at java.lang.reflect.Method.invokeNative(Native Method)
11-12 21:54:23.058: W/System.err(9625):     at java.lang.reflect.Method.invoke(Method.java:507)
11-12 21:54:23.058: W/System.err(9625):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-12 21:54:23.058: W/System.err(9625):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-12 21:54:23.058: W/System.err(9625):     at dalvik.system.NativeStart.main(Native Method)

它出现在getX

private void determineDrag(final MotionEvent event) {
        final int activePointerId = mActivePointerId;
        final int pointerIndex = getPointerIndex(event, activePointerId);
        if (activePointerId == -1)
            return;
        float x;
        float dx;
        float xDiff;
        float y;
        try {
            x = MotionEventCompat.getX(event, pointerIndex);
            dx = x - mInitMotionX;
            xDiff = Math.abs(dx);
            y = MotionEventCompat.getY(event, pointerIndex);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

Try-catch 是解决方案,但我想知道这是 Android 错误还是其他问题?

4

1 回答 1

0

这似乎是一个Android错误是的。似乎支持库在某些情况下可能没有做好(或任何)边界检查。

基本上,您最终会随机/很少崩溃, onTouchEvent()或者onInterceptTouchEvent()出现 java.lang.IllegalArgumentException: pointerIndex out of range(此处的错误报告java.lang.ArrayIndexOutOfBoundsException此处的错误报告)它似乎在人们多点触控时表现出来。很难复制。

此问题(以及类似问题)的解决方法似乎是如此子类和覆盖 onTouchEvent(),并且onInterceptTouchEvent()您可以在其中捕获这些异常并返回false请参阅此处的代码示例。

于 2014-04-30T08:53:20.373 回答