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

java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 #72

Closed
Michenux opened this issue Aug 30, 2013 · 30 comments
Closed

java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 #72

Michenux opened this issue Aug 30, 2013 · 30 comments
Labels
Milestone

Comments

@Michenux
Copy link

hi,

I try to use your library but i have the exception bellow when zoom in.

08-30 22:44:43.437  20210-20210/com.******E/AndroidRuntime: FATAL EXCEPTION: main
        java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
        at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1004)
        at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:855)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1852)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
        at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1952)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1966)
        at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1418)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2424)
        at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:255)
        at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1914)
        at android.view.View.dispatchPointerEvent(View.java:7564)
        at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3883)
        at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3778)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
        at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3483)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
        at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3540)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
        at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3429)
        at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3398)
        at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3406)
        at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3379)
        at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5419)
        at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5399)
        at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5370)
        at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5493)
        at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:182)
        at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
        at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:174)
        at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5472)
        at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5512)
        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:730)
        at android.os.Handler.dispatchMessage(Handler.java:92)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:5103)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
@Michenux
Copy link
Author

i tried to investigate a bit more.
The bug occurs when i use the DrawerLayout.

My main layout :

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"/>

</android.support.v4.widget.DrawerLayout>

The below layout is inflated in the FrameLayout content_frame

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/watchPhoto"/>
</RelativeLayout>

@tauntz
Copy link

tauntz commented Aug 31, 2013

Can confirm that this happens. This does not happen always but quite often after having added android.support.v4.widget.DrawerLayout. Haven't investigated yet if it's actually caused by PhotoView or it's a bug in DrawerLayout itself.

@JorgeDC
Copy link

JorgeDC commented Sep 2, 2013

I get the same error when running the sample and abusing the zoom. It looks like I can ignore the problem by simply catching the error in the HackyViewPager in onInterceptTouchEvent like Chris did with IllegalArgumentException.

@caiob3
Copy link

caiob3 commented Sep 12, 2013

I got the same error here when using PhotoView with android.support.v4.widget.DrawerLayout. Where should I override the:

 @Override
    public boolean onInterceptTouchEvent(MotionEvent ev)
...
...

Into my Activity or in the Fragment?

I have:

public class MainDrawerActivity extends Activity {

    private DrawerLayout mDrawerLayout;
...
...

and

public class ImageViewFragment extends Fragment {

private PhotoViewAttacher mAttacher;
...
...

Also I have:

private class PhotoTapListener  implements OnPhotoTapListener
...

and

private class MatrixChangeListener implements OnMatrixChangedListener
...

I tried in both (extending ViewGroup to override onInterceptTouchEvent) but not sure why didn't work for me.
Can anyone tell me where should I used?

@smarek
Copy link
Contributor

smarek commented Sep 12, 2013

@caiob3 , @Michenux can you link here some project demonstrating the issue, and add info about platform (what android compile target, what android version on runtime, ...)
I will try to look into it.

@ghost ghost assigned smarek Sep 12, 2013
@fluxthesky
Copy link

I have this error too, and I also use a android.support.v4.widget.DrawerLayout.

This happens when the image is at it's original size, and I attempt to zoom out, or when I zoom in the image and then zoom it out until it proceeds to crash.

@fluxthesky
Copy link

It seems that I was able to ignore the problem by simply creating a class that extends DrawerLayout, and do the same thing that Chris did with the HackyViewPager ,

@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    try {
        return super.onInterceptTouchEvent(arg0);
    } catch (Exception e) {
        // TODO Auto-generated catch block

        e.printStackTrace();
        return false;
    }
}

At least this solves the problem of crashing my app, but I will keep watch if this doesn't work.

@smarek
Copy link
Contributor

smarek commented Sep 16, 2013

@fluxthesky two qeustion sire, are you using PhotoView from dev branch or latest 1.2.1 release (maven, jar) ?
Can you create minimal project to demostrate the issue? I'll look into this today possibly.

@fluxthesky
Copy link

@smarek I'm pretty sure it's the master one.
https://github.com/chrisbanes/PhotoView/tree/master/library

I have created a minimal project but ... I don't know how to upload it to github (I'm new with this thing), so I would try to do so later at night.

But it should be quite easy to reproduce the bug, simply put a android.support.v4.widget.DrawerLayout in your layout, and try to zoom out/zoom in the image.

Also, I'm using this library based on the sample usage doc.

@smarek
Copy link
Contributor

smarek commented Sep 16, 2013

Yes, it looks like issue in Support v4 library, below is implementation equivalent to HackyViewPager for DrawerLayout. I will add the class to Sample project and close this issue after merge.

import android.content.Context;
import android.support.v4.widget.DrawerLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;

public class HackyDrawerLayout extends DrawerLayout {


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

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

    public HackyDrawerLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

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

use in layout like this

<your.application.package.HackyDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:id="@+id/drawer_layout"
    android:layout_height="match_parent">
</your.application.package.HackyDrawerLayout>

@tauntz
Copy link

tauntz commented Sep 16, 2013

Sample project: https://www.dropbox.com/s/pbykpve2xdiyfki/PhotoViewissue72Project.zip
If I would hazard a guess I'd say that the root cause of this is that the touch event stream is not fully propagated to ViewDragHelper (because of requestDisallowInterceptTouchEvent(boolean) in PhotoViewAttacher) and it gets into an inconsistent state.

@tauntz
Copy link

tauntz commented Sep 16, 2013

@smarek that'll just hide the symptoms of the issue. The root cause is still that PhotoView hides some parts of the touch event stream from other components and they get only part of the full event stream.

@smarek
Copy link
Contributor

smarek commented Sep 16, 2013

@tauntz Yes, you are probably right, solution above is just quick fix, because after initial touches (and hidden throwns), the library works as desired and exceptions are not being thrown. I will try to fix it on PhotoView level, but as of now, it is tested, we can use the same solution as in HackyViewPager.

smarek added a commit that referenced this issue Sep 16, 2013
Tested against 4.x, all functions works and the underlying ViewPager/DrawableLayout doesn't report any exceptions.
@smarek
Copy link
Contributor

smarek commented Sep 17, 2013

@tauntz Can you please verify e6cdb60, thanks

@smarek
Copy link
Contributor

smarek commented Sep 23, 2013

For maven users, you can test now against released snapshot:

Maven URL: https://oss.sonatype.org/content/repositories/snapshots/
Direct URL: https://oss.sonatype.org/content/repositories/snapshots/com/github/chrisbanes/photoview/library/
Version: 1.2.2-SNAPSHOT

@smarek
Copy link
Contributor

smarek commented Sep 24, 2013

Tested against 2.3.5 (HTC Sense 2.1, HTC Wildfire S A510e), and works properly.
That means, you can stop using HackyViewPager if you use latest support library and current dev branch (future 1.2.2 release).
Closing

@smarek smarek closed this as completed Sep 24, 2013
@xavi-
Copy link

xavi- commented Oct 17, 2013

Thank you very much for solving issue. I was running into a similar issue with my app. BTW, here's a link to the android bug: https://code.google.com/p/android/issues/detail?id=60464

@httpdispatch
Copy link
Contributor

The issue is still present in the latest dev build

@jaygridley
Copy link

I can confirm, the issue is still present in the latest dev build

@phil-brown
Copy link
Contributor

Yep, this issue is back. I wouldn't say it is still present - the old fix did seem to work.

@Benjamin-Dobell
Copy link

I'm seeing this consistently in the latest release (com.github.chrisbanes.photoview:library:1.2.3), also using a DrawerLayout.

@Benjamin-Dobell
Copy link

It would seem c1655bf was responsible for the reintroduction of this bug.

@Benjamin-Dobell
Copy link

For posterity, here's my stack-trace:

java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
            at android.support.v4.widget.ViewDragHelper.shouldInterceptTouchEvent(ViewDragHelper.java:1004)
            at android.support.v4.widget.DrawerLayout.onInterceptTouchEvent(DrawerLayout.java:868)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1859)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
            at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
            at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
            at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
            at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
            at android.view.View.dispatchPointerEvent(View.java:7886)
            at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
            at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
            at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
            at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
            at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
            at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
            at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
            at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
            at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
            at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5512)
            at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5483)
            at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5612)
            at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
            at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
            at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:176)
            at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:5585)
            at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:5631)
            at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
            at android.view.Choreographer.doCallbacks(Choreographer.java:574)
            at android.view.Choreographer.doFrame(Choreographer.java:542)
            at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

@smarek smarek reopened this Jul 8, 2014
@smarek smarek modified the milestones: 1.2.4, 1.2.2 Jul 8, 2014
eugenkiss added a commit to eugenkiss/chanobol that referenced this issue Jan 11, 2015
bherbst added a commit to bherbst/PhotoView that referenced this issue Feb 6, 2015
If the PhotoView gesture detector handles scaling or dragging the PhotoView, we will continue to block the parent view from receiving onTouch events. If the gesture detector did not scale or drag the PhotoView at all, we allow the parent to properly receive all touch events.

Tested on 4.x and 5.x in an Activity with both a NavigationDrawer and a ViewPager. Both components work as designed along with scaling/panning a PhotoView.
bherbst added a commit to bherbst/PhotoView that referenced this issue Feb 6, 2015
If the PhotoView gesture detector handles scaling or dragging the PhotoView, we will continue to block the parent view from receiving onTouch events. If the gesture detector did not scale or drag the PhotoView at all, we allow the parent to properly receive all touch events.

Tested on 4.x and 5.x in an Activity with both a NavigationDrawer and a ViewPager. Both components work as designed along with scaling/panning a PhotoView.
smarek added a commit that referenced this issue Feb 7, 2015
Fix for regression on issue #72.
@smarek smarek modified the milestones: 1.2.4, 1.2.5 Apr 2, 2015
@bhatnagar-gaurav
Copy link

Since this issue again reappeared from 1.2.3 and it is still persisting in the latest version, when a fix will be updated . Should we continue to use the temporary fix which was earlier being updated using a CustomizedDrawerlayout to prevent the crash.

@Jawnnypoo
Copy link
Contributor

Since this is a framework issue, the fix for now is to extend the problematic ViewGroup and catch the exception. See the README for more

@pwgn
Copy link

pwgn commented Mar 1, 2016

I keep getting the ArrayIndexOutOfBoundsException even though I've implemented the fix described in smareks comment.

I can see that the my ImageView is part of the HackyDrawerLayout and that the onInterceptTouchEvent in that class is run at times, but the exception is never catched when the exception occur.

This is my onInterceptTouchEvent:

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

And my xml file:

<?xml version="1.0" encoding="utf-8"?>
<co.org.app.HackyDrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ProgressBar
            android:id="@+id/progress_bar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />

        <ImageView
            android:id="@+id/image_view_image_display"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <android.support.design.widget.CoordinatorLayout
            android:id="@+id/snackbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </RelativeLayout>

</co.org.app.HackyDrawerLayout>

Any ideas?

@gabrieljuan
Copy link

I've got the error just now, same with @pwgn . but if you set the ImageView width and height to wrap_content, the error won't appear.

EDIT :
I add one more catch exception in hacky drawer layout with ArrayIndexOutOfBoundsException and I don't get the error again

@EdwardvanRaak
Copy link

Well I have the same problem and all the solutions and workaround didn't work without all kinds of other problems (like unresponsiveness). For now I chose a solution where my FrameLayout fragment container containing the PhotoViews is a different one outside my CoordinatorLayout altogether. This way the error can never occur because it's essentially a normal FrameLayout not wrapped around any other layouts.

@tasneembohra
Copy link

I am still facing this error on Galaxy S DUOS (kyleopen) Android 4.0.3 - 4.0.4. Any resolution ?

@SrishtiRoy
Copy link

will this photoView only works for a list of images?

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

No branches or pull requests