我想知道,如果我要请求进入不存在的图片网址,我将如何在imageView中设置默认图片。
这是我的代码,希望有人能帮助我。提前谢谢。
Bitmap bitmap = imageCache.get(cards.getCardID());
final ImageView image = (ImageView) view.findViewById(R.id.cardImage);
if(bitmap!=null){
image.setImageBitmap(getRoundedCornerBitmap(bitmap, 200));
} else {
if(cards.getCardListImage()!=null){
imageUrl = cards.getCardListImage();
} else {
imageUrl = BeaconAppConstants.IMAGE_IF_ABSENT;
}
ImageRequest request = new ImageRequest(imageUrl,
new Response.Listener<Bitmap>() {
@Override
public void onResponse(Bitmap arg0) {
image.setImageBitmap(arg0);
imageCache.put(cards.getCardID(), arg0);
}
},
65,
65,
Bitmap.Config.ARGB_8888,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
Log.d("Error occured", arg0.getMessage());
// set image on this line
}
});
queue.add(request);
}
这是我的logcat输出:
1-15 23:23:59.597: E/AndroidRuntime(18331): FATAL EXCEPTION: main 11-15 23:23:59.597: E/AndroidRuntime(18331): Process: com.android.bts.beaconapp, PID: 18331 11-15 23:23:59.597: E/AndroidRuntime(18331): java.lang.NullPointerException: println needs a message 11-15 23:23:59.597: E/AndroidRuntime(18331): at android.util.Log.println_native(Native Method) 11-15 23:23:59.597: E/AndroidRuntime(18331): at android.util.Log.e(Log.java:232) 11-15 23:23:59.597: E/AndroidRuntime(18331): at com.android.bts.beaconapp.adapter.BeaconCardAdapter$2.onErrorResponse(BeaconCardAdapter.java:94)