java.lang.IllegalArgumentException: pointerIndex out of range

        在做一个图片手势缩放功能的时候(多点触摸),在获取触摸点距离的时候有时候会跑出以上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)


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值