我是靠谱客的博主 诚心大山,最近开发中收集的这篇文章主要介绍完美解决java.lang.IllegalArgumentException: pointerIndex out of range,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

 

 

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

  1. E/AndroidRuntime: FATAL EXCEPTION: main
  2. Process: com.kuaijie, PID: 23303
  3. java.lang.IllegalArgumentException: pointerIndex out of range
  4. at android.view.MotionEvent.nativeGetAxisValue(Native Method)
  5. at android.view.MotionEvent.getX(MotionEvent.java:2106)
  6. at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
  7. at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
  8. at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
  9. at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1834)
  10. at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2284)
  11. at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2683)
  12. at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2399)
  13. at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2683)
  14. at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2399)
  15. at android.widget.PopupWindow$PopupViewContainer.dispatchTouchEvent(PopupWindow.java:1929)
  16. at android.view.View.dispatchPointerEvent(View.java:9124)
  17. at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4632)
  18. at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:4470)
  19. at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
  20. at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)
  21. at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)
  22. at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4153)
  23. at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)
  24. at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4210)
  25. at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
  26. at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4073)
  27. at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4039)
  28. at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4047)
  29. at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4020)
  30. at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:6480)
  31. at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:6379)
  32. at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:6350)
  33. at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:6570)
  34. at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
  35. at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
  36. at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
  37. at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:6541)
  38. at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:6593)
  39. at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
  40. at android.view.Choreographer.doCallbacks(Choreographer.java:590)
  41. at android.view.Choreographer.doFrame(Choreographer.java:558)
  42. at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
  43. at android.os.Handler.handleCallback(Handler.java:739)
  44. at android.os.Handler.dispatchMessage(Handler.java:95)
  45. at android.os.Looper.loop(Looper.java:145)
  46. at android.app.ActivityThread.main(ActivityThread.java:5835)
  47. at java.lang.reflect.Method.invoke(Native Method)
  48. at java.lang.reflect.Method.invoke(Method.java:372)
  49. at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
  50. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

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

  1. public class ViewPagerFixed extends android.support.v4.view.ViewPager {
  2. public ViewPagerFixed(Context context) {
  3. super(context);
  4. }
  5.  
  6. public ViewPagerFixed(Context context, AttributeSet attrs) {
  7. super(context, attrs);
  8. }
  9.  
  10. @Override
  11. public boolean onTouchEvent(MotionEvent ev) {
  12. try {
  13. return super.onTouchEvent(ev);
  14. } catch (IllegalArgumentException ex) {
  15. ex.printStackTrace();
  16. }
  17. return false;
  18. }
  19.  
  20. @Override
  21. public boolean onInterceptTouchEvent(MotionEvent ev) {
  22. try {
  23. return super.onInterceptTouchEvent(ev);
  24. } catch (IllegalArgumentException ex) {
  25. ex.printStackTrace();
  26. }
  27. return false;
  28. }
  29. }

 

 

 

 

 

 K.O!

最后

以上就是诚心大山为你收集整理的完美解决java.lang.IllegalArgumentException: pointerIndex out of range的全部内容,希望文章能够帮你解决完美解决java.lang.IllegalArgumentException: pointerIndex out of range所遇到的程序开发问题。

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

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

评论列表共有 0 条评论

立即
投稿
返回
顶部