当我多次访问自定义视图时,我遇到了崩溃:
11-12 21:54:23.048: W/System.err(9625): java.lang.ArrayIndexOutOfBoundsException
11-12 21:54:23.048: W/System.err(9625): at android.view.MotionEvent.getX(MotionEvent.java:972)
11-12 21:54:23.048: W/System.err(9625): at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
11-12 21:54:23.048: W/System.err(9625): at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:91)
11-12 21:54:23.048: W/System.err(9625): at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:219)
11-12 21:54:23.048: W/System.err(9625): at com.ex.app.views.PulledItem.determineDrag(PulledItem.java:399)
11-12 21:54:23.048: W/System.err(9625): at com.ex.app.views.PulledItem.onInterceptTouchEvent(PulledItem.java:290)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:960)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1015)
11-12 21:54:23.048: W/System.err(9625): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1820)
11-12 21:54:23.048: W/System.err(9625): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1176)
11-12 21:54:23.058: W/System.err(9625): at android.app.Activity.dispatchTouchEvent(Activity.java:2198)
11-12 21:54:23.058: W/System.err(9625): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1795)
11-12 21:54:23.058: W/System.err(9625): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2336)
11-12 21:54:23.058: W/System.err(9625): at android.view.ViewRoot.handleMessage(ViewRoot.java:1976)
11-12 21:54:23.058: W/System.err(9625): at android.os.Handler.dispatchMessage(Handler.java:99)
11-12 21:54:23.058: W/System.err(9625): at android.os.Looper.loop(Looper.java:150)
11-12 21:54:23.058: W/System.err(9625): at android.app.ActivityThread.main(ActivityThread.java:4277)
11-12 21:54:23.058: W/System.err(9625): at java.lang.reflect.Method.invokeNative(Native Method)
11-12 21:54:23.058: W/System.err(9625): at java.lang.reflect.Method.invoke(Method.java:507)
11-12 21:54:23.058: W/System.err(9625): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-12 21:54:23.058: W/System.err(9625): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-12 21:54:23.058: W/System.err(9625): at dalvik.system.NativeStart.main(Native Method)
它出现在getX
private void determineDrag(final MotionEvent event) {
final int activePointerId = mActivePointerId;
final int pointerIndex = getPointerIndex(event, activePointerId);
if (activePointerId == -1)
return;
float x;
float dx;
float xDiff;
float y;
try {
x = MotionEventCompat.getX(event, pointerIndex);
dx = x - mInitMotionX;
xDiff = Math.abs(dx);
y = MotionEventCompat.getY(event, pointerIndex);
} catch (Exception e) {
e.printStackTrace();
return;
}
尝试捕获是解决方案,但我想知道这个Android错误还是别的什么?
答案 0 :(得分:0)
这似乎是一个Android错误。在某些情况下,似乎支持库可能没有做好(或任何)边界检查。
基本上,您最终会遇到onTouchEvent()
或onInterceptTouchEvent()
中的java.lang.IllegalArgumentException: pointerIndex out of range
(错误报告here)或java.lang.ArrayIndexOutOfBoundsException
(错误报告{}}中的随机/很少崩溃报告here)当人们多点触摸时似乎表现出来了。这很难再现。
此问题(以及类似问题)的解决方法似乎是如此子类并覆盖onTouchEvent()
和onInterceptTouchEvent()
,您可以在其中捕获这些异常并返回false
。请参阅代码示例here。