// java.lang.IllegalArgumentException: pointerIndex out of range
// at android.view.MotionEvent.nativeGetAxisValue(Native Method)
// at android.view.MotionEvent.getY(MotionEvent.java:1989)
// at android.widget.ScrollView.onTouchEvent(ScrollView.java:575)
// at android.view.View.dispatchTouchEvent(View.java:5541)
// at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1963)
// at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1724)
網上說明:
The edge slop code could violate invariants of ScaleGestureDetector,
such as the assumption that if an ACTION_POINTER_DOWN is observed
or if getPointerCount() >= 2, then there must be at least two
active pointers to choose from. But due to the edge slop handling,
it was possible for findNewActiveIndex to return -1 in this
case, resulting in a crash.
解決方案:
在做多點觸控放大縮小,操作自己所繪製的圖形時發生這個異常,如果是操作圖片的放大縮小多點觸控不會出現這個錯誤
這個bug是Android系統原因 所以第一種方式是:
修改frameworks\base\core\jni\android_view_MotionEvent.cpp的android_view_MotionEvent_nativeGetAxisValue方法
注釋掉
if(!validatePointerIndex(env, pointerIndex, pointerCount)) {return0;}
改完後需重新編譯整個系統,然後替換lib庫,重新編譯整個系統一般需要半個多小時,這個方法就比較麻煩了
第二種方法是:捕獲IllegalArgumentException(非法參數異常)異常 即如
privatefloatspacing(MotionEvent event) {
try{
x = event.getX(0) - event.getX(1);
y = event.getY(0) - event.getY(1);
} catch(IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
第二種方法簡單有效
轉自:http://blog.csdn.net/eoeandroida/article/details/7954398