今天我想向它添加SwipeRefreshLayout:
<androID.support.v4.Widget.SwipeRefreshLayout androID:ID="@+ID/swiperefreshlayout" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/recyclerVIEw" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> </androID.support.v7.Widget.RecyclerVIEw></androID.support.v4.Widget.SwipeRefreshLayout>
在Tab1Fragment中:
@OverrIDepublic VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { VIEw vIEw = inflater.inflate(R.layout.activity_main_List,container,false); recyclerVIEw = (RecyclerVIEw) vIEw.findVIEwByID(R.ID.recyclerVIEw); staggeredGrIDLayoutManager = new StaggeredGrIDLayoutManager(3,StaggeredGrIDLayoutManager.VERTICAL); recyclerVIEw.setLayoutManager(staggeredGrIDLayoutManager); swipeRefreshLayout = (SwipeRefreshLayout) vIEw.findVIEwByID(R.ID.swiperefreshlayout); swipeRefreshLayout.setcolorSchemeResources(androID.R.color.holo_blue_bright,androID.R.color.holo_green_light,androID.R.color.holo_orange_light,androID.R.color.holo_red_light); return vIEw;}
不幸的是,当我从tab1滚动到tab2,然后回到tab1时,活动崩溃:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean androID.support.v7.Widget.RecyclerVIEw$LayoutManager.canScrollVertically()' on a null object reference at androID.support.v7.Widget.RecyclerVIEw.computeVerticalScrollOffset(RecyclerVIEw.java:1613) at androID.vIEw.VIEw.canScrollVertically(VIEw.java:12880)
但显然我已经设置了Layoutmanger!似乎交错的网格布局已经消失了……
更多Weired是,当我只是单击tab1,tab2时,Activity不会崩溃,但是当我从tab2滚动到tab1时,它崩溃了
发生了什么?谢谢!
加上整个错误日志:
12-02 16:57:59.857 28189-28189/xyz.doutu.doutu E/AndroIDRuntime: Process: xyz.doutu.doutu,PID: 28189 ava.lang.NullPointerException: Attempt to invoke virtual method 'boolean androID.support.v7.Widget.RecyclerVIEw$LayoutManager.canScrollVertically()' on a null object reference at androID.support.v7.Widget.RecyclerVIEw.computeVerticalScrollOffset(RecyclerVIEw.java:1613) at androID.vIEw.VIEw.canScrollVertically(VIEw.java:12880) at androID.support.v4.vIEw.VIEwCompatICS.canScrollVertically(VIEwCompatICS.java:35) at androID.support.v4.vIEw.VIEwCompat$ICSVIEwCompatImpl.canScrollVertically(VIEwCompat.java:1253) at androID.support.v4.vIEw.VIEwCompat.canScrollVertically(VIEwCompat.java:1695) at androID.support.v4.Widget.SwipeRefreshLayout.canChildScrollUp(SwipeRefreshLayout.java:646) at androID.support.v4.Widget.SwipeRefreshLayout.onIntercepttouchEvent(SwipeRefreshLayout.java:660) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:1961) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at androID.vIEw.VIEwGroup.dispatchtransformedtouchEvent(VIEwGroup.java:2408) at androID.vIEw.VIEwGroup.dispatchtouchEvent(VIEwGroup.java:2050) at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.superdispatchtouchEvent(PhoneWindow.java:2390) at com.androID.internal.policy.impl.PhoneWindow.superdispatchtouchEvent(PhoneWindow.java:1734) at androID.app.Activity.dispatchtouchEvent(Activity.java:2833) at androID.support.v7.vIEw.WindowCallbackWrapper.dispatchtouchEvent(WindowCallbackWrapper.java:60) at androID.support.v7.vIEw.WindowCallbackWrapper.dispatchtouchEvent(WindowCallbackWrapper.java:60) at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.dispatchtouchEvent(PhoneWindow.java:2351) at androID.vIEw.VIEw.dispatchPointerEvent(VIEw.java:8700)解决方法 将recyclerVIEw分配移动到onVIEwCreated()而不是onCreateVIEw().问题是当您的TabFragment分离并重新附加到vIEwPager滚动时. 总结
以上是内存溢出为你收集整理的android – 由于LayoutManager为NULL,RecycleView在Fragment中崩溃全部内容,希望文章能够帮你解决android – 由于LayoutManager为NULL,RecycleView在Fragment中崩溃所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)