給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);
? ? ? ? ? ? ? ?}
就不會出問題了。