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.

Expanding parent view holder -> crash

See original GitHub issue

Hi guys,

I have following set up: In a support dialog fragment I have a simple RecyclerView where the parent views should be expandable. When I press the button to expand the children the app crashes with:

java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{24819493 position=19 id=-1, oldPos=6, pLpos:6 scrap [attachedScrap] tmpDetached no parent} at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4487) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4618) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4599) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1988) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1384) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574) at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2954) at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2594)

What I noticed is, that the crash occurs at position 19, but my children list contains only 18 elements. The children list size is for each parent different.

I’m using com.android.support:recyclerview-v7:23.2.1

If you need any additional information, please let me know. Your help is appreciated 😃 Kind regards, Robert Hilse

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

6reactions
pepitoriacommented, May 3, 2016

Just figured it out.

I was going through the adapter code to tidy it up a bit to post a gist here when I realise I still had the getItemCount method from my previous default non expandable implementation.

As it was still overriding the parents getItemCount it was ok to override (no compilation errors) but of course it was not taking the sub items into consideration.

I would strongly suggest to make getItemCount in ExpandableRecyclerAdapter.java as final so we cannot override it. It is a silly thing but I am sure most of us start with a default implementation and then look how to achieve the expandable behaviour.

Hope this helps someone else too!

0reactions
paul-turnercommented, Oct 7, 2016

Added a note to the docs for now, will see if more issues like this roll in throughout the lifetime of the library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Occasional crash when expanding/collapsing group while ...
Code should not crash when expanding items while using updateAsync. ... Invalid view holder adapter positionViewHolder{1c8fea59 position=8 ...
Read more >
App gets crashed randomly while scrolling expandable list view
This crash has occurred due to Expandable List View and invoking Text Watcher. and using multiple Text Watcher's for both parent and child ......
Read more >
1651439 – gluster-NFS crash while expanding volume
Bug 1651439 - gluster-NFS crash while expanding volume ... Mount Type: --- ... None, Open, inode : prevent dentry creation if parent does...
Read more >
Expandable RecyclerView by Big Nerd Ranch - GitHub Pages
Create two ViewHolders to hold parent and child views by extending ParentViewHolder and ChildViewHolder respectively. Handle the normal ViewHolder behavior ...
Read more >
US Warns of Expanding Russia, Iran Military Partnership
Russia and Iran are expanding their military partnership, a White House spokesman said, warning that Tehran is considering supplying the ...
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