0

我使用 processing.js 编写了一个 android 应用程序!我在银河选项卡中进行多点触控缩放时遇到问题!在移动设备中没有问题,但在银河选项卡中,每当我尝试缩放时都会收到此错误:

    FATAL EXCEPTION: main
java.lang.IllegalArgumentException: pointerIndex out of range
    at android.view.MotionEvent.nativeGetAxisValue(Native Method)
    at android.view.MotionEvent.getX(MotionEvent.java:1549)
    at changethispackage.beforesubmitting.tothemarket.u2.u2.surfaceTouchEvent(u2.java:633)
    at apwidgets.MyScrollView.onTouchEvent(MyScrollView.java:20)
    at android.view.View.dispatchTouchEvent(View.java:4626)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1554)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1320)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1560)
    at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1333)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1862)
    at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1286)
    at android.app.Activity.dispatchTouchEvent(Activity.java:2315)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1835)
    at android.view.View.dispatchPointerEvent(View.java:4694)
    at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2419)
    at android.view.ViewRoot.handleMessage(ViewRoot.java:2080)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:132)
    at android.app.ActivityThread.main(ActivityThread.java:4126)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:491)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
    at dalvik.system.NativeStart.main(Native Method)
Can't parse this exception line:
FATAL EXCEPTION: main

这是缩放的代码:

   boolean surfaceTouchEvent(MotionEvent event) {
  pointNum=event.getPointerCount();
  switch (event.getAction() & MotionEvent.ACTION_MASK) {
  case MotionEvent.ACTION_POINTER_DOWN:
    // User is pressing down another finger.
    float x11 = event.getX(0) - event.getX(1);
    float y22 = event.getY(0) - event.getY(1);
    z4 = sqrt(x11*x11+y22*y22);
    break;
  case MotionEvent.ACTION_POINTER_UP:
    // User is released one of the fingers.
    break;
  case MotionEvent.ACTION_MOVE:
    x1=event.getX(0);
    x2=event.getX(1);
    y1=event.getY(0);
    y2=event.getY(1);
    float x = event.getX(0) - event.getX(1);
    float y= event.getY(0) - event.getY(1);
    float z3 = sqrt(x*x+y*y);
    println("z3:" + z3);
    if (pointNum == 2 ) {
      if ( z3 < z4 ) {
        zoom = z3/z4;
      }
      else {
        zoom = z3/z4;

      }
      zoom = constrain(zoom, 0, 100);
    }

    break;
  }
  return super.surfaceTouchEvent(event);
}

如果您知道问题,请提供帮助!

4

1 回答 1

0

问题是您正在检查案例中第一根和第二根手指的 X 和 Y 值,但是当只有一根手指在屏幕上移动时 ACTION_MOVE,您可以获得一个事件。ACTION_MOVE

如果您getX(1)在只有一根手指向下时调用,那么您会得到 ,IllegalArgumentException因为只有一根手指向下,并且您正在尝试检查第二个手指的 X 值。

解决方案是移动这条线:

if (pointNum == 2 ) {

ACTION_MOVE案例块的顶部,因为您不会关心在屏幕上移动一根手指来进行缩放事件。

我遇到了这个问题,因为我在onTouchEvent通话期间在触摸 a 的空白部分时遇到了这个异常ScrollView。请参阅此错误以了解我最终最终用于该问题的解决方法。

于 2013-06-20T15:23:04.030 回答