在我的應用程序中,我使用了抽象imageLoader,但有一個問題我無法理解。 當我只調用response.getBitmap並將其設置爲背景圖像時,它很好,但是當我爲示例System.out.println(response.getBitmap)添加一些代碼時,它會崩潰。總之,如果我只需調用respone.getBitmap就可以了,但是如果兩次或更多次崩潰。這裏有什麼問題?排隊圖像位圖爲空
public class NewsAdapter extends BaseAdapter {
private ArrayList<News> mNewsList;
private DefaultActivity mActivity;
private ImageLoader imageLoader;
private RequestQueue mRequestQueue;
public NewsAdapter(DefaultActivity pActivity, ArrayList<News> newsList){
mActivity = pActivity;
mNewsList = newsList;
mRequestQueue = Volley.newRequestQueue(mActivity);
imageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache(
BitmapLruCache.getDefaultLruCacheSize()));
}
private class ViewHolder {
public ImageView networkImageView;
public TextView title;
public TextView description;
}
@Override
public int getCount() {
return mNewsList.size();
}
@Override
public News getItem(int i) {
return mNewsList.get(i);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
final ViewHolder viewHolder;
final News news = getItem(i);
if (view == null){
final LayoutInflater li = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.orange_news_item, viewGroup, false);
viewHolder = new ViewHolder();
viewHolder.networkImageView = (ImageView)view.findViewById(R.id.imageView);
viewHolder.title = (TextView)view.findViewById(R.id.title);
viewHolder.description = (TextView)view.findViewById(R.id.description);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.title.setText(Html.fromHtml(news.getTitle()));
viewHolder.description.setText(Html.fromHtml(news.getBody()));
imageLoader.get(news.getImageThumbUrl(),new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
viewHolder.networkImageView.setImageBitmap(response.getBitmap());
System.out.println("bitmap="+response.getBitmap());
System.out.println("width="+response.getBitmap().getWidth());
System.out.println("height="+response.getBitmap().getHeight());
}
@Override
public void onErrorResponse(VolleyError error) {
//To change body of implemented methods use File | Settings | File Templates.
}
});
return view;
}
}
什麼是崩潰? –