thoughtbot / expandable-recycler-view

Custom Android RecyclerViewAdapters that collapse and expand
https://robots.thoughtbot.com/introducing-expandablerecyclerview
MIT License
2.12k stars 407 forks source link

IndexOutOfBoundsException when back button pressed #44

Closed samirthebti closed 2 months ago

samirthebti commented 7 years ago

This error appear even if i unsure the data is not empty or null in the onSaveInstace method
The trace of the Error :

java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) at java.util.ArrayList.get(ArrayList.java:308) at com.thoughtbot.expandablerecyclerview.models.ExpandableGroup.writeToParcel(ExpandableGroup.java:67) at android.os.Parcel.writeParcelable(Parcel.java:1357)

rajsuvariya commented 7 years ago

Please upload the code

abdyer commented 7 years ago

I also get this error when onSaveInstanceState is called in my fragment in response to navigating to another activity. However, this does not occur when calling the method in response to an orientation change.

abdyer commented 7 years ago

In my case, the issue was caused by the first group in the adapter having an empty list of items. Changing that to null got rid of the error.

Ideally, this line should be changed to if (items == null || items.isEmpty()) { to fix it.

rajsuvariya commented 7 years ago

items == null and items.isEmpty() are two different things. If we add this condition then the empty list would be ignored. There is a possibility that the same list is being used somewhere to add the data.

antonyhaman commented 5 years ago

There is a solution here: #104