-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Comments
i tried to investigate a bit more. 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> |
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. |
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. |
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. |
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. |
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 ,
At least this solves the problem of crashing my app, but I will keep watch if this doesn't work. |
@fluxthesky two qeustion sire, are you using PhotoView from dev branch or latest 1.2.1 release (maven, jar) ? |
@smarek I'm pretty sure it's the master one. 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. |
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> |
Sample project: https://www.dropbox.com/s/pbykpve2xdiyfki/PhotoViewissue72Project.zip |
@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. |
@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. |
Tested against 4.x, all functions works and the underlying ViewPager/DrawableLayout doesn't report any exceptions.
For maven users, you can test now against released snapshot: Maven URL: https://oss.sonatype.org/content/repositories/snapshots/ |
Tested against 2.3.5 (HTC Sense 2.1, HTC Wildfire S A510e), and works properly. |
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 |
The issue is still present in the latest dev build |
I can confirm, the issue is still present in the latest dev build |
Yep, this issue is back. I wouldn't say it is still present - the old fix did seem to work. |
I'm seeing this consistently in the latest release (com.github.chrisbanes.photoview:library:1.2.3), also using a DrawerLayout. |
It would seem c1655bf was responsible for the reintroduction of this bug. |
For posterity, here's my stack-trace:
|
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.
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.
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. |
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 |
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 @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? |
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 : |
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. |
I am still facing this error on Galaxy S DUOS (kyleopen) Android 4.0.3 - 4.0.4. Any resolution ? |
will this photoView only works for a list of images? |
hi,
I try to use your library but i have the exception bellow when zoom in.
The text was updated successfully, but these errors were encountered: