question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:30 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
smarekcommented, 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>
1reaction
pwgncommented, Mar 3, 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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix java.lang.ArrayIndexOutOfBoundsException: length ...
An Array length of 1 means that only the index 0 exist, because in java array indexes start with 0! Or in other...
Read more >
How to Fix java.lang.ArrayIndexOutOfBoundsException in ...
lang.ArrayIndexOutOfBoundsException: length=1; index=1 error because index 1 is invalid here. Why? because the index in the Java array starts with zero ...
Read more >
Array index out of bounds exception: length=1 index=1
The error message tells you that you try to access the element number 1 which is the second element in an array which...
Read more >
3 Tips to solve and Avoid java.lang ... - Javarevisited
The error ArrayIndexOutOfBoundsException: 1 means index 1 is invalid and it's out of bounding i.e. more than the length of the array. Since...
Read more >
Array Index Out Of Bounds Exception in Java - GeeksforGeeks
The index of an array is an integer value that has value in the interval [0, n-1], where n is the size of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found