当我多连接我的自定义视图时,我遇到了崩溃:
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;
}
Try-catch 是解决方案,但我想知道这是 Android 错误还是其他问题?