我正在使用ViewPager和Recyclerview,但是在创建时它会崩溃......
我正在使用Recyclerview.Adapter尝试AsyncListUtil,并且它有效。当我将片段移动到ViewPager时,它开始像这样崩溃。任何见解?
FATAL EXCEPTION: main
Process: com.dekanski.popularmovies, PID: 6554
java.lang.NullPointerException: Attempt to read from field 'int android.support.v7.widget.RecyclerView$ItemAnimator$ItemHolderInfo.left' on a null object reference
at android.support.v7.widget.SimpleItemAnimator.animateChange(SimpleItemAnimator.java:130)
at android.support.v7.widget.RecyclerView.animateChange(RecyclerView.java:3062)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2924)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3071)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.support.v4.view.ViewPager.onLayout(ViewPager.java:1627)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1037)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:747)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:761)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1466)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:579)
at android.widget.FrameLayout.onLayout(FrameLayout.java:514)
at android.view.View.layout(View.java:15671)
at android.view.ViewGroup.layout(ViewGroup.java:5038)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2086)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1843)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:4)
似乎已在支持版本23.2.1
中修复答案 1 :(得分:3)
仍然发生在23.1.1
答案 2 :(得分:2)
我已经弄清楚了......我错过了将app:layout_behavior="@string/appbar_scrolling_view_behavior"
包含在ViewPager中,因此CoordinatorLayout并不知道如何正确地完成工作。
答案 3 :(得分:1)
使用更具体的RecyclerView.Adapter.notifyDataSetChanged()
变种取代对notifyItem{Inserted,Removed,...}
的所有来电后,崩溃似乎已经消失了。
答案 4 :(得分:0)
它与23.2.0的问题。使用23.2.1:
compile 'com.android.support:design:23.2.1'