URL的域似乎包含下划线,导致图像下载失败。如果我是正确的,请告诉我
答案 0 :(得分:0)
public class LoadImage extends AsyncTask<String, String, Bitmap> {
ImageView img;
Bitmap bitmap;
Context con;
ProgressDialog pDialog;
public LoadImage(Context updateProfileActivity,
ImageView profileImageView) {
// TODO Auto-generated constructor stub
con = updateProfileActivity;
img = profileImageView;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(con);
pDialog.setMessage("Loading Image ....");
pDialog.show();
}
protected Bitmap doInBackground(String... args) {
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(args[0]).getContent());
} catch (Exception e) {
e.printStackTrace();
}
return bitmap;
}
protected void onPostExecute(Bitmap image) {
if(image != null){
img.setImageBitmap(image);
pDialog.dismiss();
}else{
pDialog.dismiss();
// Toast.makeText(MainActivity.this, "Image Does Not exist or Network Error", Toast.LENGTH_SHORT).show();
}
}
}