the code runs on galaxy s2 but crashes on galaxy tablet , please help
in
Android Processing
•
1 year ago
I write an app using processing that runs perfectly on my mobile galaxy s2 but when I'm testing it on galaxy tablet it crashes ! it opens the app but when I try to zoom in / out it gives me this error :
- FATAL EXCEPTION: main
- java.lang.IllegalArgumentException: pointerIndex out of range
so the problem is with touch event and here is the code :
- 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);
- if (pointNum == 2 ) {
- if ( z3 < z4 ) {
- zoom = z3/z4;
- }
- else{
- zoom = z3/z4;
- }
- zoom = constrain(zoom, 0, 100);
- }
- press1=event.getSize(0);
- press2=event.getSize(1);
- break;
- }
- return super.surfaceTouchEvent(event);
- }
I read somewhere that :
it's actually calling event.getX(1) when there isn't two ids. So make sure that there were two ids with event.getPointerCount() >= 2 and it will works.
1