[5.0.0-b6] Crash ClassCastException on addItem (with sticky headers)
See original GitHub issueHi, thanks in advance for the library.
I’m using v 5.0.0-b6 to implement a list with multiple sections (different AbstractFlexibleItem classes for each section) and sticky headers. At first I initialize the list with data from the DB (done using addItem() on the FlexibleAdapter). Then as soon as updated data come from my network layer I proceed doing removeItemsOfType() and addItem() again.
I often get this exception that do not happen if I disable the network layer and so no further removeItemsOfType() and addItem() is performed before the first one.
This is the method I call when data is available:
public void setOtherArticles(List<Article> otherArticles) {
removeItemsOfType(Constants.MainContent.ViewType.BOTTOM_PADDING);
removeItemsOfType(Constants.MainContent.ViewType.OTHER_ARTICLES_ITEM);
if (otherArticles.size() > 0) {
List<AbstractFlexibleItem> items = new ArrayList<>();
for (Article article : otherArticles) {
items.add(new OtherArticleItem(mOtherArticlesHeader, article));
}
int adapterPos = getItemCountOfTypes(
Constants.MainContent.ViewType.CAT_HEADER, Constants.MainContent.ViewType.CAT_ARTICLE, Constants.MainContent.ViewType.CAT_NO_ARTICLES,
Constants.MainContent.ViewType.VIDEO_ARTICLE, Constants.MainContent.ViewType.VIDEO_HEADER,
Constants.MainContent.ViewType.BLOG_ARTICLE, Constants.MainContent.ViewType.BLOG_HEADER,
Constants.MainContent.ViewType.OTHER_ARTICLES_HEADER);
addItems(adapterPos, items);
}
addItem(getItemCount(), new BottomPaddingItem(mOtherArticlesHeader));
}
Sometimes (rarely) I’ve seen the same exception as reported by tprochazka on issue #78, I don’t know if they’re related.
I don’t know if I’m doing something wrong or it is a library issue. Let me know if I can provide further info.
Here’s the exception stacktrace:
java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams at android.support.v7.widget.RecyclerView.getChildViewHolderInt(RecyclerView.java:3661) at android.support.v7.widget.RecyclerView$5.getChildViewHolder(RecyclerView.java:645) at android.support.v7.widget.ChildHelper.findHiddenNonRemovedView(ChildHelper.java:210) at android.support.v7.widget.RecyclerView$Recycler.getScrapViewForPosition(RecyclerView.java:5075) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4634) 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.GridLayoutManager.layoutChunk(GridLayoutManager.java:528) 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.GridLayoutManager.onLayoutChildren(GridLayoutManager.java:170) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2906) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3283) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122) at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1170) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:814) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586) at android.widget.LinearLayout.onLayout(LinearLayout.java:1495) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336) at android.widget.FrameLayout.onLayout(FrameLayout.java:273) at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2678) at android.view.View.layout(View.java:16636) at android.view.ViewGroup.layout(ViewGroup.java:5437) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2171) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1931) 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)
Thanks, Francesco
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:25 (12 by maintainers)
Top GitHub Comments
I’m not an expert on this, but I think that the second option with boolean parameter is the best way.
I’ve committed the changes in dev branch, please make some experiments for the definitive fix, I wait some suggestions 😃