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

Code crashed if only empty ExpandableLayout added to xml #82

Closed
ivankarpey opened this issue Jul 27, 2016 · 2 comments
Closed

Code crashed if only empty ExpandableLayout added to xml #82

ivankarpey opened this issue Jul 27, 2016 · 2 comments

Comments

@ivankarpey
Copy link

ivankarpey commented Jul 27, 2016

I have markup which looks like:

<com.github.aakira.expandablelayout.ExpandableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/placeholder"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!--<TextView xmlns:android="http://schemas.android.com/apk/res/android"-->
            <!--android:id="@+id/tv7778"-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="@dimen/input_height"-->
            <!--android:background="@drawable/border11_bottom"-->
            <!--android:gravity="center_vertical"-->
            <!--android:text="WE NEVER FORGET WE NEVER FORGIVE"/>-->

    </com.github.aakira.expandablelayout.ExpandableLinearLayout>

and if I comment textview in the middle it's fails with:

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: io.test PID: 3618
                  java.lang.ArrayIndexOutOfBoundsException: length=0; index=-1
                      at java.util.ArrayList.get(ArrayList.java:310)
                      at com.github.aakira.expandablelayout.ExpandableLinearLayout.onMeasure(ExpandableLinearLayout.java:126)
                      at android.view.View.measure(View.java:18788)
                      at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                      at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                      at android.view.View.measure(View.java:18788)
                      at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
                      at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                      at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1465)
                      at android.widget.LinearLayout.measureVertical(LinearLayout.java:748)
                      at android.widget.LinearLayout.onMeasure(LinearLayout.java:630)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
                      at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
                      at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
                      at android.view.View.measure(View.java:18788)
                      at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
                      at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
                      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
                      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
                      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
                      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
                      at android.view.Choreographer.doCallbacks(Choreographer.java:670)
                      at android.view.Choreographer.doFrame(Choreographer.java:606)
                      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
@ivankarpey
Copy link
Author

the problem is in this line:

https://github.com/AAkira/ExpandableLayout/blob/master/library/src/main/java/com/github/aakira/expandablelayout/ExpandableLinearLayout.java#L126

You consider that array will have elements and not checking case when it could be empty. So trying ti get item with -1 index.

@AAkira
Copy link
Owner

AAkira commented Sep 2, 2016

@ivankarpey

Thanks a bunch! :-)
I fixed on v1.6.0

@AAkira AAkira closed this as completed Sep 12, 2016
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

2 participants