java.lang.IllegalArgumentException: pointerIndex
java.lang.IllegalArgumentException: pointerIndex
今日竹石 发表于4年前
java.lang.IllegalArgumentException: pointerIndex
  • 发表于 4年前
  • 阅读 1684
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

摘要: 如何解决java.lang.IllegalArgumentException: pointerIndex out of range?

今天遇到一个bug:

java.lang.IllegalArgumentException: pointerIndex out of range
	at android.view.MotionEvent.nativeGetAxisValue(Native Method)
	at android.view.MotionEvent.getX(MotionEvent.java:1981)
	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.onTouchEvent(ViewPager.java:1901)
	at cn.xs8.app.activity.news.ui.CustomViewPager.onTouchEvent(CustomViewPager.java:29)
	at android.view.View.dispatchTouchEvent(View.java:7263)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2235)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1932)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
	at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2241)
	at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1946)
	at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1977)
	at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1427)
	at android.app.Activity.dispatchTouchEvent(Activity.java:2428)
	at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1925)
	at android.view.View.dispatchPointerEvent(View.java:7443)
	at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3603)
	at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3531)
	at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4783)
	at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4743)
	at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4895)
	at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
	at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
	at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
	at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4863)
	at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4917)
	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
	at android.view.Choreographer.doCallbacks(Choreographer.java:579)
	at android.view.Choreographer.doFrame(Choreographer.java:546)
	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
	at android.os.Handler.handleCallback(Handler.java:800)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:194)
	at android.app.ActivityThread.main(ActivityThread.java:5371)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:525)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
	at dalvik.system.NativeStart.main(Native Method)

     在网上很多关于该bug的处理都众说纷纭,我在这里不再详述该bug产生的原因,下面给出一种在4.1的机子上测试通过的方案:

1.让你的view(可能是ScrollView,WebView,MapView等),创建一个子view继承于它们中的某一个;

2.重写onInterceptTouchEvent 和onTouchEvent方法

3.try catch 该两个方法,形如下面:

try{  

    super.onInterceptTouchEvent(MotionEvent ev)  

catch(ILLegalArgumentException ex) {  

}  

    return false;  

  

try{  

    super.onTouchEvent(MotionEvent ev)  

catch(ILLegalArgumentException ex) {  

}  

    return false;  



共有 人打赏支持
粉丝 41
博文 228
码字总数 181721
×
今日竹石
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: