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

Expanding parent view holder -> crash #198

Closed
camino2007 opened this issue Apr 27, 2016 · 12 comments
Closed

Expanding parent view holder -> crash #198

camino2007 opened this issue Apr 27, 2016 · 12 comments
Assignees

Comments

@camino2007
Copy link

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

@MDXDave
Copy link

MDXDave commented May 1, 2016

Same issue here

FATAL EXCEPTION: main
Process: com.xxxxxx, PID: 17278
java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{1424b40 position=4 id=-1, oldPos=3, pLpos:3 scrap [attachedScrap] tmpDetached no parent} 'Internet'
at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4505)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4636)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2979)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2619)
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.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 android.view.View.measure(View.java:18788)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:668)
at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1170)
at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:733)
at android.view.View.measure(View.java:18788)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1075)
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.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
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 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.

@camino2007
Copy link
Author

I managed it by myself to expand a Recycler View. When I click on a parent I simply add the child models and remove them when I click another parent.

@paul-turner
Copy link
Contributor

@camino2007 @MDXDave I'm not able to reproduce this on the sample, any chance you can give more information on your implementation? Or better yet see if it occurs in one of our samples?

@pepitoria
Copy link

pepitoria commented May 3, 2016

same thing happens to me

FATAL EXCEPTION: main
                                                                       java.lang.IndexOutOfBoundsException: Inconsistency detected. Invalid view holder adapter positionViewHolder{42bb4ac0 position=14 id=-1, oldPos=6, pLpos:6 scrap [attachedScrap] tmpDetached no parent}
                                                                           at android.support.v7.widget.RecyclerView$Recycler.validateViewHolderForOffsetPosition(RecyclerView.java:4505)
                                                                           at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4636)
                                                                           at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
                                                                           at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
                                                                           at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
                                                                           at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
                                                                           at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
                                                                           at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:2979)
                                                                           at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2904)
                                                                           at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1482)
                                                                           at android.support.v7.widget.RecyclerView.access$400(RecyclerView.java:147)
                                                                           at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:294)
                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:591)
                                                                           at android.view.Choreographer.doFrame(Choreographer.java:560)
                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
                                                                           at android.os.Handler.handleCallback(Handler.java:730)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                           at android.os.Looper.loop(Looper.java:176)
                                                                           at android.app.ActivityThread.main(ActivityThread.java:5419)
                                                                           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:1046)
                                                                           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
                                                                           at dalvik.system.NativeStart.main(Native Method)

@pepitoria
Copy link

Not sure if this info is relevant but it always crashes on position 14 (I have a list of 14 parent items)

@paul-turner
Copy link
Contributor

@pepitoria Any chance I can get a peek at your adapter and parent view holder implementations? is anything changing the data behind the scenes? Able to reproduce with the samples?

@pepitoria
Copy link

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!

@paul-turner
Copy link
Contributor

@pepitoria Good catch! I'll wait and see if the others had this same problem as well.
Then we can see if it's something we can cut down on by making the method final as you suggest.

@pepitoria
Copy link

no problem @paul-turner, I take a pull request for just adding a 5 letter word to one java file would be a bit too much, right? haha

@paul-turner
Copy link
Contributor

paul-turner commented May 3, 2016

Well at this point I'm on the fence whether that would be OK for users of the library. If someone wants to have a more custom expandable RV and overrides some of the methods to add in some behaviours on top of our adapter. An edge case but maybe something someone relies on (I've seen one example in past issues submitted here).

At the very least may need to expand the docs to warn a little more.

@pepitoria
Copy link

true that about expanding the docs with this. Another way could be to make getItemCount as final and use your own getExpandableItemCount method that could be overridden if needed. That way it would be obvious you are just "forgetting" to delete your getItemCount method.

@paul-turner
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants