android 获取服务器数据,展示在listView报空指针

时间从来都不存在 2016-09-08 02:05:57
获取的服务器数据数组,展示在listview上,但是有些字段为空,我的listView报空指针。
{
"Status":200,
"membersList":[
{
"id":124,
"userType":0,
"createTime":"2016/09/06 10:31",
"parentId":"17828127004",
"userName":null,
"headPicture":null,
"userSex":null,
"isRegister":1
},
{
"id":127,
"userType":1,
"createTime":"2016/09/07 14:41",
"parentId":"17828127004",
"userName":"",
"headPicture":"http://192.168.0.11:8080/healthChannel/uploadFolder/20160907023850.PNG",
"userSex":"",
"isRegister":0
},
{
"id":128,
"userType":1,
"createTime":"2016/09/07 14:41",
"parentId":"17828127004",
"userName":"小",
"headPicture":"http://192.168.0.11:8080/healthChannel/uploadFolder/20160907023850.PNG",
"userSex":"男",
"isRegister":0
}
]
}
请问在这里怎么设置 userName为空的时候,给他设置其他参数呢。
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder=null;
if(convertView==null){
convertView=LayoutInflater.from(getActivity()).inflate(R.layout.item_addfamily, null);
holder=new ViewHolder();
@SuppressWarnings("unused")
TextView textView=(TextView)convertView.findViewById(R.id.item_tv_name);
@SuppressWarnings("unused")
ImageView imageView=(CircleImageView)convertView.findViewById(R.id.item_c_imageView);
convertView.setTag(holder);
}else {
holder=(ViewHolder)convertView.getTag();
}
try {
if(dataName.get(position)==null){
holder.textView.setText("小明");
}else{
holder.textView.setText(dataName.getString(position));
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

// if(dataPicture.get(position)==null){
// holder.imageView.setImageResource(R.drawable.father);
// }else if(dataPicture.get(position)!=null){
// holder.imageView.setImageResource(R.drawable.abc_menu_hardkey_panel_mtrl_mult);
// MyImageLoader.displayImage_header(dataPicture.get(position),
// holder.imageView);
// }
return convertView;
...全文
418 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
码农搬砖_2020 2016-09-09
  • 打赏
  • 举报
回复
dataName 对象是null的,所以getCount函数包空指针。 该回复由 微信公众号:码农搬砖,回复,如果回复对您有用,可以关注看看。
疯狂的兔子ccc 2016-09-09
  • 打赏
  • 举报
回复
目测getcount的dataName没有初始化
zhang106209 2016-09-08
  • 打赏
  • 举报
回复
你报的空指针是getCount(),你看一下
zhang106209 2016-09-08
  • 打赏
  • 举报
回复
你要这样判断 if(“”.equails(tn.getName)){},你的判断不对
thbdy 2016-09-08
  • 打赏
  • 举报
回复
写法好多错误
秃头地中海 2016-09-08
  • 打赏
  • 举报
回复
引用 6 楼 yangchun_dawang 的回复:
[quote=引用 4 楼 qq_33225439 的回复:] [quote=引用 3 楼 yangchun_dawang 的回复:] [quote=引用 1 楼 qq_33225439 的回复:] 看log
帮我看看呗[/quote] 对空对象引用,lz怎么初始化数据的[/quote] lz是啥意思哦[/quote] 楼主
  • 打赏
  • 举报
回复
引用 5 楼 zhang106209 的回复:
一般这样写: KaiJiangVo.DataBean tv = mData.get(position); viewHolder.danshuan.setText(tv.getName()); 如果你要判断,if(“”“.equals())应该这样
我也试过,不行哎
  • 打赏
  • 举报
回复
引用 4 楼 qq_33225439 的回复:
[quote=引用 3 楼 yangchun_dawang 的回复:] [quote=引用 1 楼 qq_33225439 的回复:] 看log
帮我看看呗[/quote] 对空对象引用,lz怎么初始化数据的[/quote] lz是啥意思哦
zhang106209 2016-09-08
  • 打赏
  • 举报
回复
一般这样写: KaiJiangVo.DataBean tv = mData.get(position); viewHolder.danshuan.setText(tv.getName()); 如果你要判断,if(“”“.equals())应该这样
秃头地中海 2016-09-08
  • 打赏
  • 举报
回复
引用 3 楼 yangchun_dawang 的回复:
[quote=引用 1 楼 qq_33225439 的回复:] 看log
帮我看看呗[/quote] 对空对象引用,lz怎么初始化数据的
  • 打赏
  • 举报
回复
引用 1 楼 qq_33225439 的回复:
看log
帮我看看呗
  • 打赏
  • 举报
回复
秃头地中海 2016-09-08
  • 打赏
  • 举报
回复
看log

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧