2017-04-18 15 views
0

我想在android上創建自定義列表視圖。我從Mysql下載了一張圖片,但是ı無法在一篇文章中下載第二張圖片。錯誤是:E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #3.從網址下載圖像到Mysql到自定義列表視圖

我的下載器代碼;

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { 
     ImageView bmImage; 

     public DownloadImageTask(ImageView bmImage) { 
      this.bmImage = bmImage; 
     } 

     protected Bitmap doInBackground(String... urls) { 
      String urldisplay = urls[0]; 
      Bitmap mIcon11 = null; 
      try { 
       InputStream in = new java.net.URL(urldisplay).openStream(); 
       mIcon11 = BitmapFactory.decodeStream(in); 
      } catch (Exception e) { 
       Log.e("Error", e.getMessage()); 
       e.printStackTrace(); 
      } 
      return mIcon11; 
     } 

     protected void onPostExecute(Bitmap result) { 
      bmImage.setImageBitmap(result); 
     } 
    } 

我用這段代碼調用;

new DownloadImageTask((ImageView)itemView.findViewById(R.id.imageView)).execute(photo); 
+0

爲什麼這個標記的PHP? – trembling

回答

0

我建議你使用滑翔,而是如果你有選擇,你會避免同步的頭痛,可以很容易地處理這些錯誤: 添加到您的依賴關係:

dependencies { 
    compile 'com.github.bumptech.glide:glide:3.7.0' 
    compile 'com.android.support:support-v4:19.1.0' 
} 

,然後

Glide.with(this).load(url).into(imageView); 

來源: https://github.com/bumptech/glide

你可以加載圖片
+0

我添加了這個庫,但新的錯誤:無法解析方法(com.example.emrah.hıomework.CustomAdapter) –

+0

Glide.with(this).load(profilpicture).into(profileimage);不能接受「這個」 –