java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
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)
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>
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. Can anyone tell me where should I used?
@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.
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 ,
@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.
@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.
@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.
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 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.
@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.
@tauntz Can you please verify e6cdb60, thanks
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
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
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.