Android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null..空指针问题,费劲心思才找到报空指针的原因:

代码是这样的,有多种布局类型

@Override
public int getItemViewType(int position) {
BmobIMMessage message = msgs.get(position);
if(message.getMsgType().equals(BmobIMMessageType.IMAGE.getType())){
return message.getFromId().equals(currentUid) ? TYPE_SEND_IMAGE: TYPE_RECEIVER_IMAGE;
}else if(message.getMsgType().equals(BmobIMMessageType.LOCATION.getType())){
return message.getFromId().equals(currentUid) ? TYPE_SEND_LOCATION: TYPE_RECEIVER_LOCATION;
}else if(message.getMsgType().equals(BmobIMMessageType.VOICE.getType())){
return message.getFromId().equals(currentUid) ? TYPE_SEND_VOICE: TYPE_RECEIVER_VOICE;
}else if(message.getMsgType().equals(BmobIMMessageType.TEXT.getType())){
return message.getFromId().equals(currentUid) ? TYPE_SEND_TXT: TYPE_RECEIVER_TXT;
}else if(message.getMsgType().equals(BmobIMMessageType.VIDEO.getType())){
return message.getFromId().equals(currentUid) ? TYPE_SEND_VIDEO: TYPE_RECEIVER_VIDEO;
}else if(message.getMsgType().equals("agree")) {//显示欢迎
return TYPE_AGREE;
}else{
// return -1;
return TYPE_AGREE;
}

然后这是

getItemCount()
@Override
public int getItemCount() {
return msgs.size(); }

最后发现是因为itemCount与viewType不匹配导致的

例如:

recyclerview总共有6种类型,现在只写了一种类型测试,其他的都没有些,才导致报空,然后在getItemCount中return 1;  就ok了

int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....的更多相关文章

  1. 报错:Binary XML file line #7: Error inflating class android.support.v7.widget.RecyclerView

    近期学习RecyclerView,使用eclipse引用RecyclerView.编写完demo后编译没有问题,一执行就挂掉,错误例如以下: 07-22 23:05:34.553: D/Android ...

  2. 配置android.support.v7.widget.Toolbar 搜索框样式

    AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...

  3. 解决 android.support.v7.widget.GridLayout 使用 xmlns:app 出现 error 的问题

    GridLayout 是在 Android API Level 14 加进来的 它可用来取代 TableLayout 也提供了自由度较大且实用的排版功能 为了兼容 4.0 以下的较低版本 Androi ...

  4. android.support.v7.widget.Toolbar 中menu图标不显示问题

    <?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http:// ...

  5. Error inflating class android.support.v7.widget.Toolbar

    建立程序的时候出现的错误 style.xml中的 <!-- Base application theme. --> <style name="AppTheme" ...

  6. Cause for NullPointerException android.support.v7.widget.RecyclerView.onMeasure

    because you have not set LinearLayoutManager to RecyclerView. for example: mRecyclerView = (Recycler ...

  7. android.support.design.widget.AppBarLayout 在android5.0+底部显示空白条问题

    在最外层使用 RelativeLayout作为根节点,同时设置 android:fitsSystemWindows="true"问题解决. <?xml version=&qu ...

  8. android.support.v7.app.AppCompatActivity不能使用的解决办法

    最近Android Studio 更新到4.0版本后,在构建项目时使用 android.support.v7.XX android.support.v4.XX 发现在xml文件中,原先我最常使用的Dr ...

  9. android.support.v7.internal.widget.ActionBarOverlayLayout Couldn't Be Initialized

    问题症状: Android Studio 1.2 (Build 141.1890965) 新建工程,自动build完成后,Layout Editor无法预览Layout文件,报错内容: Renderi ...

随机推荐

  1. 网络芯片应用:GPS公交车行驶记录仪

    项目描写叙述 佛罗里达大学学生 Miles Moody 使用WIZnet W5200以太网插板及Arduino Nano剖析了来自一个当地网页服务的HTML代码,并讲述了他每天带着公交车实时GPS坐标 ...

  2. 计蒜客第一场A

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; char ...

  3. 关于WMware Workstation出现 “”该虚拟机似乎正在使用中“”解决办法

    如图 直接到配置文件D:\centos1\这个目录下 将vmdk.lck文化删除 然后重新打开虚拟机便可进入 问题解决

  4. BZOJ 3629 约数和定理+搜索

    呃呃 看到了这道题 没有任何思路-- 百度了一发题解 说要用约数和定理 就查了一发 http://baike.so.com/doc/7207502-7432191.html (不会的可以先学习一下) ...

  5. C++中冒号(:)的作用

    摘于:http://blog.csdn.net/zimingjushi/article/details/6549390 (1)表示机构内位域的定义(即该变量占几个bit空间) typedef stru ...

  6. 学习总结--Dom

    节点(每个元素都会有的3个nodeValue nodeType nodeName:) 1 元素节点 nodeName 元素节点名 nodeType 1 nodeValue null或者undefine ...

  7. PHP date()获取某时间段以周、月、季度为粒度的时间段数组

    date()函数: PHP date()  参考:https://www.hi-docs.com/php/date.html Linux date()参考:http://www.cnblogs.com ...

  8. [Python] Manage Dependencies with Python Virtual Environments

    Virtual Environments ensure that dependencies from one Python application don’t overwrite the depend ...

  9. J2EE之13个规范标准概念

    主要是关于j2EE十三个规范的总结. java基础知识 首先java分为三类:J2ME.J2SE.J2EE. 依据开发软件的大小和量级他们的作用分别不同,J2ME是开发为机顶盒.移动电话和PDA之类嵌 ...

  10. 智课雅思词汇---二、词根acu和acr

    智课雅思词汇---二.词根acu和acr 一.总结 一句话总结:acu和acr:sharp锋利的,敏捷的: acuteacutelyacuity sharp锋利的,敏捷的 1.词根acr表示什么意思? ...