在做一个图片手势缩放功能的时候(多点触摸),在获取触摸点距离的时候有时候会跑出以上java.lang.IllegalArgumentException: pointerIndex out of range异常,在网上没有查到比较好的解决方法,有一个是直接捕获异常,把这个异常忽略了就没事了,总觉得这样欠佳,求高手指点下。
出错地点代码:
float dx = event.getX(1) - event.getX(0);
float dy = event.getY(1) - event.getY(0);
异常信息:
01-02 02:55:10.375: E/AndroidRuntime(1267):FATAL EXCEPTION: main
01-02 02:55:10.375: E/AndroidRuntime(1267):java.lang.IllegalArgumentException: pointerIndex out of range
01-02 02:55:10.375: E/AndroidRuntime(1267): at android.view.MotionEvent.nativeGetAxisValue(NativeMethod)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.MotionEvent.getX(MotionEvent.java:1974)
01-02 02:55:10.375: E/AndroidRuntime(1267): at com.mediaplayer.luo.PlayPictureActivity$OnPicTouchListener.distance(PlayPictureActivity.java:299)
01-02 02:55:10.375: E/AndroidRuntime(1267): at com.mediaplayer.luo.PlayPictureActivity$OnPicTouchListener.onTouch(PlayPictureActivity.java:259)
01-02 02:55:10.375: E/AndroidRuntime(1267): at android.view.View.dispatchTouchEvent(View.java:5536)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
01-02 02:55:10.375: E/AndroidRuntime(1267): atcom.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1931)
01-02 02:55:10.375: E/AndroidRuntime(1267): atcom.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1390)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.app.Activity.dispatchTouchEvent(Activity.java:2364)
01-02 02:55:10.375: E/AndroidRuntime(1267): atcom.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1879)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.View.dispatchPointerEvent(View.java:5721)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2890)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewRootImpl.performTraversals(ViewRootImpl.java:859)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.os.Handler.dispatchMessage(Handler.java:99)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.os.Looper.loop(Looper.java:137)
01-02 02:55:10.375: E/AndroidRuntime(1267): atandroid.app.ActivityThread.main(ActivityThread.java:4432)
01-02 02:55:10.375: E/AndroidRuntime(1267): atjava.lang.reflect.Method.invokeNative(Native Method)
01-02 02:55:10.375: E/AndroidRuntime(1267): atjava.lang.reflect.Method.invoke(Method.java:511)
01-02 02:55:10.375: E/AndroidRuntime(1267): atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
01-02 02:55:10.375: E/AndroidRuntime(1267): atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
01-02 02:55:10.375: E/AndroidRuntime(1267): atdalvik.system.NativeStart.main(Native Method)