davideas / FlexibleAdapter

Fast and versatile Adapter for RecyclerView which regroups several features into one library to considerably improve the user experience :-)
Apache License 2.0
3.55k stars 553 forks source link

Fatal Exception: java.lang.IllegalStateException: Two different ViewHolders have the same stable ID #738

Open yaroslav-shlapak opened 5 years ago

yaroslav-shlapak commented 5 years ago

Got several crashes from different users in Crashlytics, but never in development. I suppose it is somehow related to the hashcode and equals overriding for children of AbstractHeaderItem and AbstractFlexibleItem, however I'm pretty sure they are correct. What else might be a reason?

Here is how I configure FlexibleAdapter:

    fun setUpHomepageFlexibleAdapter(
            adapter: FlexibleAdapter<AbstractFlexibleItem<*>>,
            view: View?,
            setUpFastScroller: (FastScroller?) -> Unit
    ) {
        adapter.setNotifyMoveOfFilteredItems(true)
        val fastScroller: FastScroller? = view?.findViewById(R.id.fastScroller)
        setUpFastScroller(fastScroller)
        adapter.fastScroller = fastScroller

        adapter
                .setAnimationOnForwardScrolling(false)
                .setAnimationOnReverseScrolling(false)
        adapter
                .setUnlinkAllItemsOnRemoveHeaders(true)
                .setDisplayHeadersAtStartUp(true)
                .setStickyHeaders(true)
    }

Stacktrace:

Fatal Exception: java.lang.IllegalStateException: Two different ViewHolders have the same stable ID. Stable IDs in your adapter MUST BE unique and SHOULD NOT change.
 ViewHolder 1:ViewHolder{e138b17 position=0 id=91973136, oldPos=-1, pLpos:-1} 01 | Requisition Efficiency 
 View Holder 2:ViewHolder{8f47449 position=8 id=91973136, oldPos=-1, pLpos:-1 not recyclable(1)} 01 | 
Requisition Efficiency androidx.recyclerview.widget.RecyclerView{90c659e VFED..... ......ID 0,0-1080,1409 #7f080076 app:id/elementsRecycler}, adapter:com.app.homepage.c@771987f,
layout:eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager@90ed04c, context:com.metricinsights.viewer.presentation.main.MainActivity@27ea8bb
       at androidx.recyclerview.widget.RecyclerView.handleMissingPreInfoForChangeError + 4058(RecyclerView.java:4058)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep3 + 3982(RecyclerView.java:3982)
       at androidx.recyclerview.widget.RecyclerView.dispatchLayout + 3652(RecyclerView.java:3652)
       at androidx.recyclerview.widget.RecyclerView.onLayout + 4194(RecyclerView.java:4194)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.FrameLayout.layoutChildren + 323(FrameLayout.java:323)
       at android.widget.FrameLayout.onLayout + 261(FrameLayout.java:261)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at androidx.swiperefreshlayout.widget.SwipeRefreshLayout.onLayout + 625(SwipeRefreshLayout.java:625)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at com.google.android.material.appbar.HeaderScrollingViewBehavior.layoutChild + 142(HeaderScrollingViewBehavior.java:142)
       at com.google.android.material.appbar.ViewOffsetBehavior.onLayoutChild + 41(ViewOffsetBehavior.java:41)
       at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onLayoutChild + 1556(AppBarLayout.java:1556)
       at androidx.coordinatorlayout.widget.CoordinatorLayout.onLayout + 888(CoordinatorLayout.java:888)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.FrameLayout.layoutChildren + 323(FrameLayout.java:323)
       at android.widget.FrameLayout.onLayout + 261(FrameLayout.java:261)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at androidx.constraintlayout.widget.ConstraintLayout.onLayout + 1915(ConstraintLayout.java:1915)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.FrameLayout.layoutChildren + 323(FrameLayout.java:323)
       at android.widget.FrameLayout.onLayout + 261(FrameLayout.java:261)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.FrameLayout.layoutChildren + 323(FrameLayout.java:323)
       at android.widget.FrameLayout.onLayout + 261(FrameLayout.java:261)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.FrameLayout.layoutChildren + 323(FrameLayout.java:323)
       at android.widget.FrameLayout.onLayout + 261(FrameLayout.java:261)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.LinearLayout.setChildFrame + 1812(LinearLayout.java:1812)
       at android.widget.LinearLayout.layoutVertical + 1656(LinearLayout.java:1656)
       at android.widget.LinearLayout.onLayout + 1565(LinearLayout.java:1565)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.widget.FrameLayout.layoutChildren + 323(FrameLayout.java:323)
       at android.widget.FrameLayout.onLayout + 261(FrameLayout.java:261)
       at com.android.internal.policy.DecorView.onLayout + 1042(DecorView.java:1042)
       at android.view.View.layout + 22399(View.java:22399)
       at android.view.ViewGroup.layout + 6572(ViewGroup.java:6572)
       at android.view.ViewRootImpl.performLayout + 3340(ViewRootImpl.java:3340)
       at android.view.ViewRootImpl.performTraversals + 2804(ViewRootImpl.java:2804)
       at android.view.ViewRootImpl.doTraversal + 1850(ViewRootImpl.java:1850)
       at android.view.ViewRootImpl$TraversalRunnable.run + 8455(ViewRootImpl.java:8455)
       at android.view.Choreographer$CallbackRecord.run + 949(Choreographer.java:949)
       at android.view.Choreographer.doCallbacks + 761(Choreographer.java:761)
       at android.view.Choreographer.doFrame + 696(Choreographer.java:696)
       at android.view.Choreographer$FrameDisplayEventReceiver.run + 935(Choreographer.java:935)
       at android.os.Handler.handleCallback + 873(Handler.java:873)
       at android.os.Handler.dispatchMessage + 99(Handler.java:99)
       at android.os.Looper.loop + 214(Looper.java:214)
       at android.app.ActivityThread.main + 6981(ActivityThread.java:6981)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 493(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main + 1445(ZygoteInit.java:1445)
runaloop commented 4 years ago

Have the very same crashes, have you fixed it?

NStreet8579 commented 4 years ago

Hi @davideas, can you please help, i'm also getting same kind of crashes on notifyItemChanged(int position).