java.lang.IllegalArgumentException: pointerIndex out of range
I meet the same error:
07-03 16:26:21.961 9001-9001/com.yuele.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
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.onInterceptTouchEvent(ViewPager.java:1834)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1944)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2358)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2063)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2075)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1524)
at android.app.Activity.dispatchTouchEvent(Activity.java:2528)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2023)
at android.view.View.dispatchPointerEvent(View.java:7532)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3682)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3610)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4862)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4822)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4974)
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:4942)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4996)
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:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5349)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:853)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:133)
at dalvik.system.NativeStart.main(Native Method)
When I zoom it to minimal size,this error happened.
+1
edit:
After search, i have the bug on viewPager only and to solve it i need to use HackyViewPager from sample.
+1
don't want to use another library to fix it.Any better ways here?
+1
+1
Use HackyViewPager instead of ViewPager to solve this issue
yes! Use HackyViewPager instead of ViewPager to solve this issue. Or,user your custom viewpager just override onInterceptTouchEvent and catch the IllegalArgumentException exception
I have the same issue, why would I want to go and use yet another library to solve an issue with the existing one... The fix (called workaround #4 somewhere) is already implemented in the branch that I pulled last night and the code that was supposed to fix this is already there and it still happens.
Reproducible if you zoom out really quickly.
+1
java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:1983)
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:1839)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2059)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2430)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2172)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2314)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1692)
at android.app.Activity.dispatchTouchEvent(Activity.java:2739)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2275)
at android.view.View.dispatchPointerEvent(View.java:8578)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:4021)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3887)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3578)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3635)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3502)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3468)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3476)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3449)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5701)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5675)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5646)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5791)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:143)
at android.os.Looper.loop(Looper.java:122)
at android.app.ActivityThread.main(ActivityThread.java:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
this is my way
public class DetailViewPager extends ViewPager {
private int mode = 0;
public DetailViewPager(Context context) {
super(context);
}
public DetailViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
/**
* 修复 java.lang.IllegalArgumentException: pointerIndex out of range pointerIndex=-1 pointerCount=1 bug
* 传说此bug是系统bug
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException e) {
e.printStackTrace();
return false;
}
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mode = 1;
break;
case MotionEvent.ACTION_UP:
mode = 0;
break;
case MotionEvent.ACTION_POINTER_UP:
mode -= 1;
break;
case MotionEvent.ACTION_POINTER_DOWN:
mode += 1;
return false;
case MotionEvent.ACTION_MOVE:
if (mode >= 2) {
return false;
}
break;
}
return super.onTouchEvent(event);
}
}
The HackyViewPager included in the sample project fixed it for me
+1 for me with the v1.2.3. I have downgraded PhotoView library version to 1.2.2 and it works well.
Ok, I went with HackyViewPager as all above were saying and it did work out well. I hesitated because I thought it would be more than 1 class, I hadn't even looked at what the suggestion was, at first.
Solution is to use HackyViewPager
The HackyViewPager doesn't give a smooth effect in my experience though just a little tweak makes wonders instead of catching IllegalArgumentException in onInterceptTouchEvent() if we catch it in the call to super's onTouchEvent() everything remains butter smooth.
HackViewPager works perfectly.
Done!
Most helpful comment
https://github.com/chrisbanes/PhotoView/blob/master/sample/src/main/java/uk/co/senab/photoview/sample/HackyViewPager.java
Done!