這裏是我的代碼來加載圖像從服務器...有什麼不對? 應用程序無法加載任何東西,並顯示了強制停止error.I的代碼中刪除的部分,我敢肯定,這就是工作...爲什麼我的代碼無法加載任何圖像?
public class MenuAdapter extends BaseAdapter{
private LayoutInflater myInflater;
private List<String> labelIDs = new ArrayList<String>();
private List<String> imageIDs = new ArrayList<String>();
public void setData(List<String> values, List<String> images){
this.labelIDs = values;
this.imageIDs = images;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
try {
URL url = new URL("url"+imageIDs.get(position));
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
holder.ivIcon.setImageBitmap(bmp);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
holder.tvLabel.setText(labelIDs.get(position));
return convertView;
}
static class ViewHolder {
ImageView ivIcon;
TextView tvLabel;
}
}
你是什麼意思?那是對的。你收到的錯誤是什麼? – TejjD