1
我是新來的android開發,所以忍受着我。Android /處理MotionEvent getX()引發異常
我寫了一個處理腳本,可以同時使用兩臺印刷機。爲此,我使用android.view.motionevent。在我的主要腳本(pde)中,我有這個:
public boolean surfaceTouchEvent(MotionEvent event) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
//do action down stuff...
}
//etc do other actions...
這工作正常。問題就來了在處理ACTION_MOVE:
FATAL EXCEPTION: main
java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:1974)
at processing.test.scrapeashape.ScrapeAShape.surfaceTouchEvent(ScrapeAShape.java:131)
at processing.core.PApplet$SketchSurfaceView.onTouchEvent(Unknown Source)
at android.view.View.dispatchTouchEvent(View.java:5604)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2060)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1829)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1917)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1376)
at android.app.Activity.dispatchTouchEvent(Activity.java:2364)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1865)
at android.view.View.dispatchPointerEvent(View.java:5784)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2894)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2470)
at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2479)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
輸出只是異常之前是:
//ACTION_MOVE
else if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
int pointercount = event.getPointerCount();
print("pointercount: " + str(pointercount));
for (int i = 0; i<pointercount; i++) {
int pointerId = event.getPointerId(i);
print("i: " + str(i));
print("pointerid: " + str(pointerId));
movex[pointerid] = event.getX(pointerId);
movey[pointerid] = event.getY(pointerId);
}
}
當第二異常被產生的第一指針升空之前
pointercount: 1
i: 0
pointerid: 1
所以有一個指針的指針id是1.顯然getX()引發異常,但我不明白爲什麼,因爲我是usin g由event.getPointerId()給出的指針id。
任何想法?