ChildHelper.java第352和355行崩溃

时间:2019-02-06 20:24:48

标签: android android-recyclerview crash recyclerview-layout

我们的应用程序具有一个使用RecyclerView构建的listView,并且在不同的用例上添加,删除,移动,更改了项目,并且我使用了默认动画

以下是与Android中的ChildHelper类相关的1000次崩溃,以下是使应用程序崩溃的代码,该代码可在https://android.googlesource.com/platform/frameworks/support/+/5031b30/v7/recyclerview/src/android/support/v7/widget/ChildHelper.java#352

获得
void unhide(View view) {
        final int offset = mCallback.indexOfChild(view);
        if (offset < 0) {
            throw new IllegalArgumentException("view is not a child, cannot hide " + view);
        }
        if (!mBucket.get(offset)) {
            throw new RuntimeException("trying to unhide a view that was not hidden" + view);
        }
        mBucket.clear(offset);
        unhideViewInternal(view);
    }

会导致这两个错误的用例是什么?我们如何避免这些情况?

这是这两种情况的崩溃日志。

崩溃日志,记录了未隐藏的观看者的情况。

Fatal Exception: java.lang.RuntimeException: trying to unhide a view that was not hiddenandroid.widget.FrameLayout{dd0c169 V.E...... ......ID 0,54-680,234}
   at android.support.v7.widget.ChildHelper.unhide(ChildHelper.java:355)
   at android.support.v7.widget.RecyclerView$Recycler.getScrapOrHiddenOrCachedHolderForPosition(RecyclerView.java:6124)
   at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5627)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5589)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5585)
   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2231)
   at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1558)
   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1518)
   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:610)
   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3719)
   at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3135)
   at android.view.View.measure(View.java:19826)
   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
   at android.view.View.measure(View.java:19826)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:911)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
   at android.view.View.measure(View.java:19826)
   at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
   at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6164)
   at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:719)
   at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
   at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
   at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:789)
   at android.view.View.measure(View.java:19826)
   at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1060)
   at android.view.View.measure(View.java:19826)
   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6164)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
   at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6164)
   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6164)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6164)
   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6164)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
   at com.android.internal.policy.DecorView.onMeasure(DecorView.java:692)
   at android.view.View.measure(View.java:19826)
   at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2351)
   at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1423)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1672)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1299)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6558)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
   at android.view.Choreographer.doCallbacks(Choreographer.java:683)
   at android.view.Choreographer.doFrame(Choreographer.java:619)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
   at android.os.Handler.handleCallback(Handler.java:751)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:6316)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

视图不是孩子的情况

Fatal Exception: java.lang.IllegalArgumentException: view is not a child, cannot hide android.widget.FrameLayout{202da5c V.E...... ........ 0,81-1020,351}
   at android.support.v7.widget.ChildHelper.unhide(ChildHelper.java:352)
   at android.support.v7.widget.RecyclerView$Recycler.getScrapOrHiddenOrCachedHolderForPosition(RecyclerView.java:6124)
   at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5627)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5589)
   at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5585)
   at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2231)
   at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1558)
   at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1518)
   at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:610)
   at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3719)
   at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:3135)
   at android.view.View.measure(View.java:23297)
   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
   at android.view.View.measure(View.java:23297)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:958)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
   at android.view.View.measure(View.java:23297)
   at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
   at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
   at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:719)
   at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
   at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1361)
   at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:789)
   at android.view.View.measure(View.java:23297)
   at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1060)
   at android.view.View.measure(View.java:23297)
   at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
   at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
   at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
   at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
   at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
   at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6928)
   at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
   at com.android.internal.policy.DecorView.onMeasure(DecorView.java:899)
   at android.view.View.measure(View.java:23297)
   at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2881)
   at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1911)
   at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2166)
   at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1780)
   at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7827)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
   at android.view.Choreographer.doCallbacks(Choreographer.java:723)
   at android.view.Choreographer.doFrame(Choreographer.java:658)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
   at android.os.Handler.handleCallback(Handler.java:789)
   at android.os.Handler.dispatchMessage(Handler.java:98)
   at android.os.Looper.loop(Looper.java:164)
   at android.app.ActivityThread.main(ActivityThread.java:6944)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

0 个答案:

没有答案