LinearLayoutManager layoutManager = new LinearLayoutManager(this);
recycleView.setLayoutManager(layoutManager);这一行报空指针
错误信息:
FATAL EXCEPTION: main
Process: com.create.bicdroid, PID: 4997
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.defaultOnMeasure(int, int)' on a null object reference
at android.support.v7.widget.RecyclerView$LayoutManager.onMeasure(RecyclerView.java:8144)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2614)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1486)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:765)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:647)
at com.zhy.autolayout.AutoLinearLayout.onMeasure(AutoLinearLayout.java:43)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1486)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:765)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:647)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.zhy.autolayout.AutoFrameLayout.onMeasure(AutoFrameLayout.java:64)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1486)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:765)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:647)
at com.zhy.autolayout.AutoLinearLayout.onMeasure(AutoLinearLayout.java:43)
at android.view.View.measure(View.java:18948)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5976)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2713)
at android.view.View.measure(View.java:18948)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2158)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1252)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1488)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1143)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6256)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:886)
at android.view.Choreographer.doCallbacks(Choreographer.java:698)
at android.view.Choreographer.doFrame(Choreographer.java:633)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:872)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5665)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)

是在onmesure()方法中报错,网上解释的比较合理的原因是 这句代码必须是oncreate方法中调用,因为要计算空间尺寸,但是别的类也是同样的用法,就不会出现该错误。

RecyclerView的坑的更多相关文章

  1. RecyclerView 踩坑

    一.RecyclerView设置拖动后怎么监听拖动的开始和结束 ItemTouchHelper helper = new ItemTouchHelper(new ItemTouchHelper.Cal ...

  2. 安卓易学,爬坑不易——腾讯老司机的RecyclerView局部刷新爬坑之路

    针对手游的性能优化,腾讯WeTest平台的Cube工具提供了基本所有相关指标的检测,为手游进行最高效和准确的测试服务,不断改善玩家的体验.目前功能还在免费开放中. 点击地址:http://wetest ...

  3. 安卓易学,爬坑不易—腾讯老司机的RecyclerView局部刷新爬坑之路

    前言 安卓开发者都知道,RecyclerView比ListView要灵活的多,但不可否认的里面的坑也同样埋了不少人.下面让我们看看腾讯开发工程师用实例讲解自己踩坑时的解决方案和心路历程. 话说有图有真 ...

  4. RecyclerView 与 Scrollview 搭配使用的两个坑

    RecyclerView & Scrollview & wrap_content RecyclerView wrap_content 用android.support.v4.widge ...

  5. 再说Android RecyclerView局部刷新那个坑

      RecyclerView局部刷新大家都遇到过,有时候还说会遇见图片闪烁的问题. 优化之前的效果: 优化之后的效果: 如果想单独更新一个item,我们通常会这样做,代码如下: mLRecyclerV ...

  6. Android RecyclerView局部刷新那个坑

    关键:public final void notifyItemChanged(int position, Object payload) RecyclerView局部刷新大家都遇到过,有时候还说会遇见 ...

  7. 【Android】【踩坑日记】RecyclerView获取子View的正确姿势

    开发过程中发现RecyclerView.getChildAt(position)为空的情况,但是明明这个position却没有越界. 解决办法:用recycler.getLayoutManager() ...

  8. Android中RecyclerView用法,一步一步教你如何使用RecyclerView以及带你走过编码中可能会出现的坑~

    首先,要明白RecyclerView是做什么的?其次是为什么要用RecyclerView?这里牵扯到RecyclerView和ListView的区别,这里不废话,大家自行百度即可! 以下示例我用的An ...

  9. Android开发学习之路-RecyclerView使用初探

    在进行一些MaterialDesign规范开发的时候,比如之前说到的CoordinateLayout实现的向上折叠效果的时候,如果依然使用ListView,那么这种效果是做不出来的,因为ListVie ...

随机推荐

  1. ueditor编辑器使用

    下载ueditor1_4_3_3-gbk-asp 解压后重命名为ueditor上传至网站 在需要编辑器的位置增加asp代码: <td style="PADDING-LEFT: 10px ...

  2. Thinkphp框架

    MVC思想: 1. 简单来说, M 即模型, m是Model的第一个字母,它用于管理程序的数据,因此它也是连接我们的PHP程序和数据库的功能.通常在模型类这一块,框架通常会使用ORM(对象关系映射). ...

  3. Thinking in Java——笔记(17)

    Containers in Depth Full container taxonomy You can usually ignore any class that begins with " ...

  4. macOS 10.12 解决模拟器不流畅的一段命令行

    sudo sysctl -w kern.timer.coalescing_enabled=0

  5. Android Unable to instantiate activity: Didn't find class on path

    Android Unable to instantiate activity: Didn't find class on path After i spend a while on this prob ...

  6. SQL语句 - MERGE INTO 、Cross/Outer Apply用法理解

    MERGE INTO 语法: MERGE INTO table_name alias1 USING (table|view|sub_query) alias2ON (join condition) W ...

  7. js获取cookie 和 模仿php的&_GET方法

    //获取get参数 function _get(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)( ...

  8. 如何给main传参数

    main 函数的参数有连个argc argcv[]  argc 是参数个数 argcv是参数的数组指针,且argcv的第一个参数是默认程序路径加程序名 给main传参数,需要在命令行启动程序时设置 如 ...

  9. DataTable/集合 转 Json

    前端用的jqueryUI框架获取json格式数据绑定显示表格. 后端通过WebService获取的数据是DataTable. 现将获取DataTable转Json,也支持将数据集合转Json. 一.项 ...

  10. Actor模型前奏

    软件系统从观察者模式到事件驱动然后再到消息驱动,经过了不断的抽象.当软件通过消息来交互的时候再没有了直接引用,没有了耦合,所有的一切都变成了异步和并行