Я получаю следующее исключение
Exception java.lang.IllegalArgumentException: pointerIndex out of range
android.view.MotionEvent.nativeGetAxisValue (MotionEvent.java)
android.view.MotionEvent.getX (MotionEvent.java:2141)
android.support.v4.view.ViewPager.onInterceptTouchEvent
(ViewPager.java:2092)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2254)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2400)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2400)
android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:2711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2400)
com.android.internal.policy.DecorView.superDispatchTouchEvent
(DecorView.java:416)
com.android.internal.policy.PhoneWindow.superDispatchTouchEvent
(PhoneWindow.java:1837)
android.app.Activity.dispatchTouchEvent (Activity.java:3154)
com.android.internal.policy.DecorView.dispatchTouchEvent
(DecorView.java:378)
android.view.View.dispatchPointerEvent (View.java:10177)
android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent
(ViewRootImpl.java:4634)
android.view.ViewRootImpl$ViewPostImeInputStage.onProcess
(ViewRootImpl.java:4502)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:3953)
android.view.ViewRootImpl$InputStage.onDeliverToNext
(ViewRootImpl.java:4006)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:3972)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:3980)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:3953)
android.view.ViewRootImpl$InputStage.onDeliverToNext
(ViewRootImpl.java:4006)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:3972)
android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:4101)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:3980)
android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:4158)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:3953)
android.view.ViewRootImpl$InputStage.onDeliverToNext
(ViewRootImpl.java:4006)
android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:3972)
android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:3980)
android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:3953)
android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:6443)
android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:6417)
android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:6378)
android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent
(ViewRootImpl.java:6577)
android.view.InputEventReceiver.dispatchInputEvent
(InputEventReceiver.java:185)
android.view.InputEventReceiver.nativeConsumeBatchedInputEvents
(InputEventReceiver.java)
android.view.InputEventReceiver.consumeBatchedInputEvents
(InputEventReceiver.java:176)
android.view.ViewRootImpl.doConsumeBatchedInput (ViewRootImpl.java:6525)
android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run
(ViewRootImpl.java:6600)
android.view.Choreographer$CallbackRecord.run (Choreographer.java:871)
android.view.Choreographer.doCallbacks (Choreographer.java:683)
android.view.Choreographer.doFrame (Choreographer.java:613)
android.view.Choreographer$FrameDisplayEventReceiver.run
(Choreographer.java:857)
android.os.Handler.handleCallback (Handler.java:751)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:154)
android.app.ActivityThread.main (ActivityThread.java:6310)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:872)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)
У меня есть 2 просмотрщика в приложении. Оба являются обычными - один возвращает false в onInterceptTouchEvent. У другого есть попытка catch, реализованная в onInterceptTouchEvent. Как эта ошибка возникает тогда? Добавлен код для 2 просмотрщиков ниже
public class BottomBarViewPager extends ViewPager {
public BottomBarViewPager(Context context) {
super(context);
}
public BottomBarViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
return false;
}
}
public class GalleryViewPager extends ViewPager {
public static final String TAG = GalleryViewPager.class.getSimpleName();
private boolean swipeEnabled;
public GalleryViewPager(Context context, AttributeSet attributes) {
super(context, attributes);
this.swipeEnabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent te) {
if (this.swipeEnabled) {
return super.onTouchEvent(te);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent me) {
if (this.swipeEnabled) {
/*
This is caused by a bug in ViewPager and a solution is to catch the Exception
and continue on. This only happens if you quickly tap with 2 fingers in different
locations, rapidly.
*/
try {
return super.onInterceptTouchEvent(me);
} catch (IllegalArgumentException ex) {
// SinclairLogger.e(TAG, "Caught exception in onInterceptTouchEvent", ex);
}
}
return false;
}
public void setPagingEnabled(boolean enabled) {
this.swipeEnabled = enabled;
}
}
Добавлен код для зрителей в соответствии с запросом