完美解决java.lang.IllegalArgumentException: pointerIndex out of range

感谢大神分享的精彩内容,完美解决我的问题,再次备份笔记。

1.在做多点触控放大缩小,操作自己所绘制的图形时发生这个异常。错误展示:

E/AndroidRuntime: FATAL EXCEPTION: main
                                                             Process: com.kuaijie, PID: 23303
                                                             java.lang.IllegalArgumentException: pointerIndex out of range
                                                                 at android.view.MotionEvent.nativeGetAxisValue(Native Method)
                                                                 at android.view.MotionEvent.getX(MotionEvent.java:2106)
                                                                 at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
                                                                 at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
                                                                 at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
                                                                 at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1834)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2284)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2683)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2399)
                                                                 at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2683)
                                                                 at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2399)
                                                                 at android.widget.PopupWindow$PopupViewContainer.dispatchTouchEvent(PopupWindow.java:1929)
                                                                 at android.view.View.dispatchPointerEvent(View.java:9124)
                                                                 at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4632)
                                                                 at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4470)
                                                                 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
                                                                 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)
                                                                 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)
                                                                 at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4153)
                                                                 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)
                                                                 at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4210)
                                                                 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
                                                                 at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)
                                                                 at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)
                                                                 at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)
                                                                 at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
                                                                 at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6480)
                                                                 at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6379)
                                                                 at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6350)
                                                                 at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6570)
                                                                 at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
                                                                 at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
                                                                 at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
                                                                 at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6541)
                                                                 at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6593)
                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:590)
                                                                 at android.view.Choreographer.doFrame(Choreographer.java:558)
                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
                                                                 at android.os.Handler.handleCallback(Handler.java:739)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                 at android.os.Looper.loop(Looper.java:145)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:5835)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

2.自定义ViewPager,重写onTouchEvent 和onInterceptTouchEvent。解决方案:

public class ViewPagerFixed extends android.support.v4.view.ViewPager {
    public ViewPagerFixed(Context context) {
        super(context);
    }

    public ViewPagerFixed(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        try {
            return super.onTouchEvent(ev);
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        }
        return false;
    }
}

 

 

 

 

完美解决java.lang.IllegalArgumentException: pointerIndex out of range_第1张图片

 K.O!
 

你可能感兴趣的:(Android,bug修复)