我是靠谱客的博主 留胡子老虎,最近开发中收集的这篇文章主要介绍Android 中 java.lang.IllegalArgumentException: pointerIndex out of range 异常的处理方法,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:2189)
at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:86)
at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:184)
at android.support.v4.view.ViewPager.onTouchEvent(ViewPager.java:1462)
at android.view.View.dispatchTouchEvent(View.java:8149)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2416)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2140)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2422)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2155)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2295)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1622)
at android.app.Activity.dispatchTouchEvent(Activity.java:2565)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2243)
at android.view.View.dispatchPointerEvent(View.java:8357)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4778)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4644)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4336)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4393)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4256)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4225)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4233)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4202)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6569)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6486)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6457)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6422)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6649)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:131)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
经调查,发现这是 Android 的 ViewPager 的一个 bug,偶尔会在用户执行多点触控操作时发生。直到至少 Android 4.4,该问题依然存在。

解决方案也很简单,覆写 ViewPager 的 onTouchEvent 与 onInterceptTouchEvent 方法,catch 该异常即可,如下所示:

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


最后

以上就是留胡子老虎为你收集整理的Android 中 java.lang.IllegalArgumentException: pointerIndex out of range 异常的处理方法的全部内容,希望文章能够帮你解决Android 中 java.lang.IllegalArgumentException: pointerIndex out of range 异常的处理方法所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(54)

评论列表共有 0 条评论

立即
投稿
返回
顶部