relativeLayout.setOnTouchListener((v, event) -> {
if (event == null) {
return false;
}else{
try {
scaleGestureDetector.onTouchEvent(MotionEvent.obtain(event));
} catch (Exception ex) {
}
}
...
return false;
})
scaleGestureDetector.onTouchEvent(MotionEvent.obtain(event)) causese the following exception occasionally:
Class: java.lang.IllegalArgumentException
Stack trace: java.lang.IllegalArgumentException: invalid pointerIndex 0 for MotionEvent { action=MOVE, pointerCount=0, historySize=4, eventTime=603786531923251, downTime=603786191066000, deviceId=5, source=TOUCHSCREEN, displayId=0, eventId=-1007465244}
at android.view.MotionEvent.nativeGetRawAxisValue(MotionEvent.java)
at android.view.MotionEvent.getRawX(MotionEvent.java:3196)
at android.view.GestureDetector.onTouchEvent(GestureDetector.java:598)
at android.view.ScaleGestureDetector.onTouchEvent(ScaleGestureDetector.java:275)
Relevant code:
scaleGestureDetector = new ScaleGestureDetector(getActivity(), new ScaleListener());
private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
try {
...
} catch (Exception ex) {
}
return true;
}
}
Again, scaleGestureDetector.onTouchEvent(MotionEvent.obtain(event)) throws the exception only occasionally. Could anyone shed some light on this?