int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....
来源:互联网 发布:js正则表达式数字范围 编辑:程序博客网 时间:2024/05/20 23:40
今天在做一个即时通讯回话列表时,遇到int 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()
@Overridepublic int getItemCount() { return msgs.size();}
最后发现是因为itemCount与viewType不匹配导致的
例如:
recyclerview总共有6种类型,现在只写了一种类型测试,其他的都没有些,才导致报空,然后在getItemCount中return 1; 就ok了
0 1
- int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....
- Attempt to write to field 'int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a
- android.support.v7.widget.RecyclerView$LayoutManager.canScrollVertically()’ on a null object 问题解决
- Attempt to invoke virtual method 'void android.support.v7.widget.ContentFrameLayout.setId(int)' on a
- android.support.v7.widget.RecyclerView的使用
- at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:1764)
- Android Eclipse Error inflating class android.support.v7.widget.RecyclerView
- Didn't find class "android.support.v7.widget.RecyclerView"
- Error inflating class android.support.v7.widget.RecyclerView
- Didn't find class "android.support.v7.widget.RecyclerView"
- 解决Error inflating class android.support.v7.widget.RecyclerView
- 解决Error inflating class android.support.v7.widget.RecyclerView
- Error inflating class android.support.v7.widget.RecyclerView
- java.lang.NullPointerException at android.support.v7.widget.RecyclerView.computeVerticalScrollOffset
- Error inflating class android.support.v7.widget.RecyclerView
- java.lang.NullPointerException at android.support.v7.widget.RecyclerView.computeVerticalScrollOffse
- android.support.v7.app.AppCompatActivity.getSupportActionBar()' on a null object reference
- RecyclerView$LayoutManager.onMeasure(android.support.v7.widget.RecyclerView$Recycler, android.suppor
- Android搭建HTTP服务,作为MediaPlayer的播放源来播放音频
- 2017湖南多校第五场-A(1043): Biorhythms
- 正则匹配之匹配网页img
- java xml dom4j 创建 修改 解析
- 右键新建没有Word怎么办?右键新建添加Word方法!
- int android.support.v7.widget.RecyclerView$ViewHolder.mItemViewType' on a null.....
- 《Centos服务器版安装教程》
- Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) C. Bear and Company(DP)
- hydra的使用方法
- 好的喜剧演员可能都是闷蛋
- 后续把笔记中的内容搬到博客上来,QAQ~~~~~
- LeetCode 算法刷题(12)
- 最大字段和DP
- MySQL常见错误