我是靠谱客的博主 诚心大山,最近开发中收集的这篇文章主要介绍完美解决java.lang.IllegalArgumentException: pointerIndex out of range,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
完美解决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;
- }
- }
K.O!
最后
以上就是诚心大山为你收集整理的完美解决java.lang.IllegalArgumentException: pointerIndex out of range的全部内容,希望文章能够帮你解决完美解决java.lang.IllegalArgumentException: pointerIndex out of range所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复