Skip to content
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

pointerIndex out of Range error #5

Open
Davit-Al opened this issue Jan 19, 2016 · 4 comments
Open

pointerIndex out of Range error #5

Davit-Al opened this issue Jan 19, 2016 · 4 comments

Comments

@Davit-Al
Copy link

Sometimes I get this error when I am scrolliing. Here is stacktrace:

java.lang.IllegalArgumentException: pointerIndex out of range
at android.view.MotionEvent.nativeGetAxisValue(Native Method)
at android.view.MotionEvent.getX(MotionEvent.java:2069)
at co.dift.ui.SwipeToAction$1.onTouch(SwipeToAction.java:91)
at android.view.View.dispatchTouchEvent(View.java:7784)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)

@daniil-pastuhov
Copy link

I have the same error. Just to drag left-right is enough. device 4.2.2

@hadidez
Copy link

hadidez commented Dec 14, 2016

same problem ...

@riki-dexter
Copy link

+1. Same problem

@imlk0
Copy link

imlk0 commented Jun 2, 2018

I found this page:
https://blog.csdn.net/nnmmbb/article/details/28419779
It may be a bug of Android system.

I have read the source code of SwipeToAction, and find it set an onTouchListener

...
private void init() {
        recyclerView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent ev) {
                switch (ev.getAction() & MotionEvent.ACTION_MASK) {
                    case MotionEvent.ACTION_DOWN: {
                        // http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
                        activePointerId = ev.getPointerId(0);
...
...
                    case MotionEvent.ACTION_MOVE: {
                        final int pointerIndex = ev.findPointerIndex(activePointerId);
                        final float x = ev.getX(pointerIndex);// crash here!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                        final float dx = x - downX;
...

It doesn't check the validity of the pointerIndex , so it crashed.
I don't want to edit the source code,
I avoid it by extends the RecycleView and override the setOnTouchListener method,
in the setOnTouchListener method, I construct a static proxy of the true OnTouchListener created by SwipeToAction.
and warp the true onTouch method with try{...}catch block, which catched the Exception.

my code:


public class FixExceptionRecycleView extends RecyclerView {
    private static final String LOG_TAG = "FixExceptionRecycleView";

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

    public FixExceptionRecycleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public FixExceptionRecycleView(Context context, @Nullable AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public void setOnTouchListener(OnTouchListener l) {
        super.setOnTouchListener(new FixExceptionOnTouchListener(l));
    }


    static class FixExceptionOnTouchListener implements OnTouchListener {

        private final OnTouchListener proxyedListener;

        public FixExceptionOnTouchListener(OnTouchListener proxyedListener) {
            this.proxyedListener = proxyedListener;
        }

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            try {
                return this.proxyedListener.onTouch(v, event);
            } catch (IllegalArgumentException e) {
                Log.i(LOG_TAG, "IllegalArgumentException catched", e);
            }
            return false;
        }
    }
}

@riki-dexter @hadidez @daniil-pastuhov @DatoAlxanishvili

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants