java.lang.IllegalArgumentException: pointerIndex

今天遇到一个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;  



你可能感兴趣的:(java.lang.IllegalArgumentException: pointerIndex)