New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IllegalArgumentException (pointerIndex out of range) while using many fingers to zoom in and out #31

Closed
adrien-aubel opened this Issue Feb 10, 2013 · 33 comments

Comments

Projects
None yet
@adrien-aubel

adrien-aubel commented Feb 10, 2013

(Android 4.2.1 - Samsung Galaxy Nexus)

java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:1981)
at android.support.v4.view.MotionEventCompatEclair.getX(MotionEventCompatEclair.java:32)
at android.support.v4.view.MotionEventCompat$EclairMotionEventVersionImpl.getX(MotionEventCompat.java:86)
at android.support.v4.view.MotionEventCompat.getX(MotionEventCompat.java:184)
at android.support.v4.view.ViewPager.onInterceptTouchEvent(ViewPager.java:1339)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1817)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2174)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1953)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1405)
at android.app.Activity.dispatchTouchEvent(Activity.java:2410)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1901)
at android.view.View.dispatchPointerEvent(View.java:7419)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3220)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3165)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4292)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4271)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4363)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:179)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:171)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:4342)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:4382)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
at android.view.Choreographer.doCallbacks(Choreographer.java:562)
at android.view.Choreographer.doFrame(Choreographer.java:530)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5191)
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:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)

@jitesh-dedhiya

This comment has been minimized.

jitesh-dedhiya commented Feb 12, 2013

Me too facing this issue...Any update on it..like how to fix this..?

@bunjix

This comment has been minimized.

bunjix commented Feb 27, 2013

Same crash. It happened when i try to scroll to the edge of image when image are zoomed in

@zaur

This comment has been minimized.

zaur commented Mar 3, 2013

same for me...

@MartinRajniak

This comment has been minimized.

MartinRajniak commented Mar 7, 2013

This happens even when you zoom out a lot.

@DHuckaby

This comment has been minimized.

DHuckaby commented Mar 15, 2013

+1

@txuslee

This comment has been minimized.

txuslee commented Mar 19, 2013

LGE Nexus 4 showed the same issue.

Solved with this until a better solution comes up.

@kongsonida

This comment has been minimized.

kongsonida commented Apr 11, 2013

I got crash like you too.....

@Vovaxo

This comment has been minimized.

Vovaxo commented Apr 23, 2013

@azibug

This comment has been minimized.

azibug commented Jun 21, 2013

It's the android ViewPager's bug
stackoverflow's report: http://stackoverflow.com/questions/6919292/pointerindex-out-of-range-android-multitouch
android's report: http://code.google.com/p/android/issues/detail?id=18990

My simple's method to fix this bug:
You can extends the ViewPager class, your own ViewPager should override the onTouchEvent and the onInterceptTouchEvent methods, and try-catch the IllegalArgumentException exception. Then use your own ViewPager class in layout or others you want.

Examples:

/** Custom your own ViewPager to extends support ViewPager. java source: */
/** Created by azi on 2013-6-21.  */

package com.chaokuadi.android.support.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class ViewPagerFixed extends android.support.v4.view.ViewPager {

    public ViewPagerFixed(Context context) {
        super(context);
    }

    public ViewPagerFixed(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        try {
            return super.onTouchEvent(ev);
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        }
        return false;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        }
        return false;
    }
}
/** ViewPager layout */
<?xml version="1.0" encoding="utf-8"?>
<com.chaokuaidi.android.support.view.ViewPagerFixed xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
@Tooroop

This comment has been minimized.

Tooroop commented Jul 19, 2013

azibug's solution is working for me. Thx!

@meablelee2013

This comment has been minimized.

meablelee2013 commented Jul 27, 2013

@azibug your solution is can work,thanks!

@huynguyen92

This comment has been minimized.

huynguyen92 commented Aug 13, 2013

Great, azibug!!!! it work for me, many thanks!

@StingerAJ

This comment has been minimized.

StingerAJ commented Sep 10, 2013

@chrisbanes Isn't this bug already fixed with the HackyViewPager in the sample?

@smarek

This comment has been minimized.

Contributor

smarek commented Sep 16, 2013

This issue is directly related to #72, using HackyViewPager or HackyDrawerLayout you can ommit the exception and continue to use the application. #72 will aim to fix the cause, and remove the need of using custom layout components definition.

@ghost ghost assigned smarek Sep 16, 2013

@ghost

This comment has been minimized.

ghost commented Sep 16, 2013

I have the similar problem, using the HackyViewPager, in a Android 2.3.6 device... the problem persists...

@smarek

This comment has been minimized.

Contributor

smarek commented Sep 16, 2013

@felipepx Are you sure you use right XML definition? Can you paste a stacktrace in this thread? What version of Support v4 library?

@ghost

This comment has been minimized.

ghost commented Sep 16, 2013

@smarek, I saved the log yesterday but accidentally I have deleted it from my desktop. The log was similar to the first post. I'm using the newest version of the library and also using the HackyPagerView. I have tested in my cousin's device, my devices have Android 4.2.2+ :(

sc20130915-225639

private ViewPager mViewPager;

in the onCreate Method:

mViewPager = (HackyViewPager) this.findViewById(R.id.hackyViewPager1);
ReaderAdapter rAdapter = new ReaderAdapter(imagesPaths);
mViewPager.setAdapter(rAdapter);
mViewPager.setOnPageChangeListener(this);

My ReaderAdapter:

    static class ReaderAdapter extends PagerAdapter {
        String[] images;

        public ReaderAdapter(String[] images){
            this.images = images;

        }

        @Override
        public int getCount() {
            return images.length;
        }

        @Override
        public View instantiateItem(ViewGroup container, int position) {
            PhotoView photoView = new PhotoView(container.getContext());
            photoView.setImageBitmap(returnBitmap(images[position]));
            container.setFocusableInTouchMode(true);
            container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            container.setBackgroundColor(Color.BLACK);          
            return photoView;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        public Bitmap returnBitmap(String filepath){
            File imagefile = new File(filepath);
            FileInputStream fis = null;
            try {
                fis = new FileInputStream(imagefile);
                } catch (FileNotFoundException e) {
                e.printStackTrace();
            }

            Bitmap bm = BitmapFactory.decodeStream(fis);
            return bm;
        }

    }

My HackyViewPager:

public class HackyViewPager extends ViewPager {

    public HackyViewPager(Context context) {
        super(context);
    }

    public HackyViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

}

And my layout XML file:

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 Jake Wharton

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <uk.co.senab.photoview.HackyViewPager
        android:id="@+id/hackyViewPager1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000" >
    </uk.co.senab.photoview.HackyViewPager>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="#aaffffff"
        android:descendantFocusability="beforeDescendants"
        android:focusableInTouchMode="true"
        android:gravity="center" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:gravity="center"
        android:text="@string/reader_page"
        android:textSize="12dp"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/currentPageText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginTop="2dp"
        android:layout_toRightOf="@+id/textView1"
        android:ems="3"
        android:gravity="center"
        android:inputType="number"
        android:textColor="#1c8fdc"
        android:textSize="12dp"
        android:textStyle="bold" >

    </EditText>

    <TextView
        android:id="@+id/pageText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/currentPageText"
        android:gravity="center"
        android:text="TextView"
        android:textSize="12dp"
        android:textStyle="bold" />

    </RelativeLayout>

</RelativeLayout>

This are working perfectly on my Android 4.2.2+ devices.... the crash only occurs if I'm testing on the Android 2.3.6 device...

@smarek

This comment has been minimized.

Contributor

smarek commented Sep 16, 2013

@felipepx please obtain the stacktrace, as it is important to me to know, whether your issue is this one or not.
Also are you using latest release (1.2.1) or the dev branch?
I see nothing wrong with your code, maybe just try to use dev version of HackyViewPager, where the methods are onTouchEvent and onInterceptTouchEvent, see the @azibug post above.

@ghost

This comment has been minimized.

ghost commented Sep 16, 2013

I'm using the latest release 1.2.1. I'm using only the Dev Version of HackyViewPager

@smarek

This comment has been minimized.

Contributor

smarek commented Sep 16, 2013

@felipepx Try please dev version of PhotoView with HackyViewPager from sample in dev and give me know. Thanks

@ghost

This comment has been minimized.

ghost commented Sep 17, 2013

@smarek So far no error occurred using the dev version.... Thanks 👍

@tomyZhou

This comment has been minimized.

tomyZhou commented Jun 4, 2014

My problem is also resolved with azibug's method, 3ku~~~~

@levelibeeka

This comment has been minimized.

levelibeeka commented Aug 1, 2014

Thanks Azibug, it works fine!

@kenyee

This comment has been minimized.

kenyee commented Aug 20, 2014

is Dev version = 1.3-SNAPSHOT?
Could you release it on maven central as 1.3?
-SNAPSHOT is for betas/dev versions...

@notHide

This comment has been minimized.

notHide commented Feb 14, 2015

@azibug Thx very much!!!!!!

@zahid--ali

This comment has been minimized.

zahid--ali commented Jun 9, 2016

Can someone help me here. I facing the same issue. I am using HackPageViewer the solution proposed by @azibug but still I am not able to resolve it.

@tortabevonas

This comment has been minimized.

tortabevonas commented Jun 9, 2016

@zahid--ali Can't you just catch and ignore the exception where it pops up?

@schmidtGabriel

This comment has been minimized.

schmidtGabriel commented Sep 6, 2017

@azibug nice solution. Works perfect. Thx

@UkTheScientist

This comment has been minimized.

UkTheScientist commented Sep 10, 2017

an easier solution than @azibug that worked for me is to override dispatchTouchEvent(MotionEvent ev) like this in your activity class that contains the view pager. But I am not sure if its the correct way.

@Override 
public boolean dispatchTouchEvent(MotionEvent ev){
        try {
            return super.dispatchTouchEvent(ev)
        }catch (Exception e){
            e.printStackTrace()
            return true
        }
  }
@yao23

This comment has been minimized.

yao23 commented Nov 13, 2017

@UkTheScientist solution doesn't work for me with com.android.support:support-v4:26.1.0 and API 26.

@iamriajul

This comment has been minimized.

iamriajul commented Nov 24, 2017

@azibug Thanks, it is working perfectly.

@zippo88888888

This comment has been minimized.

zippo88888888 commented Jan 9, 2018

非常感谢,完美的解决了这个问题 Thanks a lot, the perfect solved the problem

tateisu added a commit to tateisu/SubwayTooter that referenced this issue Nov 12, 2018

facebook-github-bot added a commit to facebook/react-native that referenced this issue Dec 26, 2018

android: worked around onTouchEvent exception
Summary: Catch `IllegalArgumentException: ReactViewPager.onTouchEvent` and ignore it (but log something) to work around this known bug in the Android SDK per chrisbanes/PhotoView#31 (comment). Note that `onInterceptTouchEvent()` is already doing the same thing.

Reviewed By: yungsters

Differential Revision: D13550425

fbshipit-source-id: 9fa3a7a0ca0cd95aafa3bcae6a59e0d1e690b564
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment