0

I wrote an android app using processing.js ! I have problem with multitouch zoom in galaxy tab ! in mobile there's no problem but in galaxy tab whenever I try to zoom recieve this error :

    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

here is the code for zoom :

   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);
}

please help if you know the problem !

Aida E
  • 1,108
  • 2
  • 22
  • 40

1 Answers1

0

The issue is that you're checking the X and Y values for the first and second fingers in the ACTION_MOVE case, but you can get an ACTION_MOVE event when only one finger is moved on the screen.

If you call getX(1) when only one finger is down, then you'll get the IllegalArgumentException because only one finger is down, and you're trying to check the X value for the second.

The solution would be to move this line:

if (pointNum == 2 ) {

to the top of the ACTION_MOVE case block, since you wouldn't care about moving one finger on the screen for a zoom event.

I ran across this question because I was getting this exception during an onTouchEvent call while touching an empty portion of a ScrollView. See this bug for the workaround I eventually ended up using for that issue.