drakeet / MultiType

Flexible multiple types for Android RecyclerView.
Apache License 2.0
5.76k stars 749 forks source link

When I repeat the add fragment in activty, the following error occurs occasionally. #241

Closed PWJiang closed 5 years ago

PWJiang commented 5 years ago

What kind of issue is this?

Process: com.yoohhe.lishou, PID: 31984 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference at me.drakeet.multitype.MultiTypeAdapter.indexInTypesOf(MultiTypeAdapter.java:339) at me.drakeet.multitype.MultiTypeAdapter.getItemViewType(MultiTypeAdapter.java:207) at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5926) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858) at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854) at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230) at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557) at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517) at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612) at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4194) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:142) at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:41) at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1556) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:888) at android.view.View.layout(View.java:20672) at android.view.ViewGroup.layout(ViewGroup.java:6194) at com.scwang.smartrefresh.layout.SmartRefreshLayout.onLayout(SmartRefreshLayout.java:623)

Info:
Description: MultiType is used in the fragment, the activity contains a fragment, and I repeatedly open and close the activity.
Reproduction Steps: I repeatedly open and close the activity.
My thoughts: I do not know why。
What did I do: I tried debugging for a long time and didn't solve it.
drakeet commented 5 years ago

This error message indicates that you passed a null object to the items, resulting in an NPE, and you need to check your items data.

PWJiang commented 5 years ago

This error message indicates that you passed a null object to the items, resulting in an NPE, and you need to check your items data.

Yes, this is a correct answer, I have solved it, thank you