java – 来自支持v.23.2.0的RecyclerView的dissapearence动画中的NullPointerException

前端之家收集整理的这篇文章主要介绍了java – 来自支持v.23.2.0的RecyclerView的dissapearence动画中的NullPointerException前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
在新的RecyclerView中,我们可以使用wrap_content作为高度(或宽度).所以谷歌修复了错误https://code.google.com/p/android/issues/detail?id=74772

但最终并非一切都很顺利.

从RecyclerView中删除项目时,我尝试使用消失的动画.
所以我使用适配器的方法 – notifyItemRemoved(int)与任何参数和RecyclerView导致NullPointerException.

Xml代码

...
    <RecyclerView
        android:id="@+id/RecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        android:overScrollMode="always"/>
    ...

日志:

E/AndroidRuntime: FATAL EXCEPTION: main
 java.lang.NullPointerException
     at android.support.v7.widget.SimpleItemAnimator.animateDisappearance(SimpleItemAnimator.java:78)
     at android.support.v7.widget.RecyclerView.animateDisappearance(RecyclerView.java:3246)
     at android.support.v7.widget.RecyclerView.access$700(RecyclerView.java:147)
     at android.support.v7.widget.RecyclerView$4.processDisappeared(RecyclerView.java:422)
     at android.support.v7.widget.ViewInfoStore.process(ViewInfoStore.java:231)
     at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3086)
     at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2914)
     at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3277)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
     at android.view.View.layout(View.java:14015)
     at android.view.ViewGroup.layout(ViewGroup.java:4373)
     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
     at android.view.Choreographer.doCallbacks(Choreographer.java:562)
     at android.view.Choreographer.doFrame(Choreographer.java:532)
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
     at android.os.Handler.handleCallback(Handler.java:725)
     at android.os.Handler.dispatchMessage(Handler.java:92)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:5227)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:511)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
     at dalvik.system.NativeStart.main(Native Method)

也许有这些问题的临时解决方法

编辑

我试图在新项目中重现.所以没有抛出异常.也许在我的项目中还有其他依赖关系来调用这个问题.

解决方法

我有与问题中提出的错误完全相同的错误,事实上已经为此引发了Google的错误.在深入研究框架代码之后,我确实发现我可以通过将HasFixedSize的设置从FALSE更改为TRUE来解决问题,即“rv.setHasFixedSize(true)”.这基本上告诉RecyclerView,对其内容的更改不会改变RecyclerView的大小,从而避免了完整的布局.由于对其含义的错误解释,我原本设置了这个假.这一改变为我排除了故障,是一种可重复的解决方案.

猜你在找的Java相关文章