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.

[5.0.0-b6] Crash ClassCastException on addItem (with sticky headers)

See original GitHub issue

Hi, 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:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:25 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
bornestcommented, Jun 6, 2016

I’m not an expert on this, but I think that the second option with boolean parameter is the best way.

1reaction
davideascommented, Jun 2, 2016

I’ve committed the changes in dev branch, please make some experiments for the definitive fix, I wait some suggestions 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sticky header crash on page load - Stack Overflow
I have a sticky nav bar header which follow the scrolling of the page to stay on the top. In general it works...
Read more >
Sticky Headers: 5 Ways to Make Them Better
Here are 5 tips to ensure that your sticky header's design helps, not hinders, your users.
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