给listview里面的view添加对应的图片
@Override
public void getView(int position, View convertView, ViewGroup parent) {
SquaredImageView view = (SquaredImageView) convertView;
if (view == null) {
view = new SquaredImageView(context);
}
String url = getItem(position);
Picasso.with(mContext).load(data.getImgUrl()).into(imageview);//这一行导致了程序崩溃
}
报错提示 java.lang.IllegalArgumentException: Path must not be empty.,意味着要检查string是否为空,
将以上代码修改为(包括string为空的判断,以及默认图片添加,防止了string为空的情况出现)
if (data.getImgUrl() ==null && !data.getImgUrl().isEmpty()) {
Picasso.with(mContext).load(data.getImgUrl()).into(viewHolder.iv_img);
} else {
Picasso.with(mContext).load(R.drawable.assistant).into(viewHolder.iv_img);
}
就不会出问题了。