RecyclerView$ViewHolder.shouldIgnore()

NullPointerException - Attempt to invoke virtual method RecyclerView$ViewHolder.shouldIgnore()' on a null object reference

我想给RecyclerView动态的add一个头view,但是报出了这样的错误。

解决方案

I found the source of this problem. Within RecyclerView.dispatchLayoutStep3(), there's a for loop, "for (int i = 0; i < count; ++i)", where count is based on mChildHelper.getChildCount(). While this iteration is occurring, the collection managed by ChildHelper is modified by ChildHelper.hideViewInternal(), which results in null being returned from the call to mChildHelper.getChildAt() on line 3050 of RecyclerView, which in turn results in null being returned from getChildViewHolderInt() on the same line of code (RecyclerView:3050).
Here's the chain of method calls that results in the modification that breaks the integrity of the for loop:
dispatchLayoutStep3() -> animateChange() -> addAnimatingView() -> hide() -> hideViewInternal()
When ChildHelper adds the child param to its mHiddenViews collection, it violates the integrity of the for loop way up in dispatchLayoutStep3().

I see two workarounds for this: 
1>Disable change animation in your RecyclerView 
2>Downgrade to 23.1.1, where this wasn't a problem

看到这就有点懵比了,但是项目需求就是一个列表,索性直接拿ListView来替换RecyclerView.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 说到无聊经济,首先我们要先来解释一下,什么是无聊经济。 无聊经济是在平凡的世界当中,我们创造出来的一种消磨时间的一...
    梦鹿是一只猫阅读 3,833评论 0 1
  • 这一天,好混乱。 写不完的作业,忙不完的事情。 心情过山车般上上下下。为自己的专业能力担忧。为自己的语言能力担忧。...
    莎伦小姐阅读 825评论 0 0
  • 4.26《极简生活 简而美的活》 【day45盈盈】 身边的小确幸,当我们做自己想做的事,买自己真正需要的东西时,...
    苏小盈阅读 838评论 0 0
  • (一) 一个有个性的女孩 初识小夏时, 看到一个 低头 含羞 浅笑 的女孩在那静静的坐着。 那天阳光明媚, 如女孩...
    潇湘雨妃阅读 3,895评论 0 1