zoukankan      html  css  js  c++  java
  • RecyclerView一个奇怪的npe异常

    java.lang.NullPointerException
    at android.support.v7.widget.RecyclerView.computeVerticalScrollOffset(RecyclerView.java:1613)
    at android.view.View.canScrollVertically(View.java:12016)
    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 com.leo.enjoytime.view.SwipyRefreshLayout.canChildScrollUp(SwipyRefreshLayout.java:644)
    at com.leo.enjoytime.view.SwipyRefreshLayout.onInterceptTouchEvent(SwipyRefreshLayout.java:744)

    原因是:

    recyclerview is showing but no layout manager is set

    解决办法:

    you can just ensure that the layoutmanager for the recyclerview is set before you display the recyclerview with the scrollbars property set.

    在recycleView被初始化之后需要setlayoutManager

    recyclerView = (RecyclerView) rootView.findViewById(R.id.recycle);
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));

    参考:

    http://stackoverflow.com/questions/29005644/rendering-problems-java-lang-nullpointerexception-at-android-support-v7-widget?s=1|3.6524

    http://stackoverflow.com/questions/26737113/java-lang-nullpointerexception-at-android-support-v7-widget-recyclerview-onmeasu

  • 相关阅读:
    UVA10740 Not the Best (K短路)
    UVA10967 The Great Escape(最短路)
    UVA 10841 Lift Hopping in the Real World(dijkstra)
    U盘启动的PE系统的制作方法
    让远程桌面支持多用户
    学习的书的下载地址
    刚安装完的vs2008写的ajax应用提示sys未定义
    AS3 Libs
    禁用触发器
    Microsoft .NET 类库开发的设计准则
  • 原文地址:https://www.cnblogs.com/krislight1105/p/5272023.html
Copyright © 2011-2022 走看看