java.lang.IllegalArgumentException: pointerIndex out of range Exception - dispatchTouchEvent
There is a bug in 2.1 (Eclair) where the pointer index isn't checked and is sometimes -1. You can create a custom view that extends ViewPager, override onTouchEvent and wrap the call to super.onTouchEvent in a try/catch. Whilst not a very pretty fix, I remember that it has no side effects (like missed touch events).
Adding to the above answer Also you can try Overriding onInterceptTouchEvent method and surround super.onInterceptTouchEvent(ev) with try and catch worked for me in a ViewPager
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException ex) {
ex.printStackTrace();
}
return false;
}
I had the same problem and I created a custom ViewPager to catch the exception. Here is the solution in kotlin
:
class CustomViewPager : ViewPager {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean =
try {
super.onInterceptTouchEvent(ev)
} catch (e: IllegalArgumentException) {
//uncomment if you really want to see these errors
//e.printStackTrace();
false
}
}