2014-05-09 22 views
8

URL'den bir ImageView'e resim yüklemeye çalışıyorum ama hata meydana geliyor: SkImageDecoder :: Factory null. Bunu nasıl düzeltebilirim? ÇözüldüAndroid SkImageDecoder :: Fabrika döndürdü null Hata

private class LoadImageFromURL extends AsyncTask<String, Void, Bitmap>{ 
     ImageView bitmapImgView; 
     public LoadImageFromURL(ImageView bmImgView){ 
      bitmapImgView = bmImgView; 
     } 

     @Override 
     protected Bitmap doInBackground(String... params) { 
      // TODO Auto-generated method stub 
      String urlStr = params[0]; 
      Bitmap img = null; 
      try { 
       URL url = new URL(urlStr); 
       InputStream inputStream = url.openConnection().getInputStream(); 
       //Options bmFactoryOpt = new Options(); 
       //bmFactoryOpt.inJustDecodeBounds = false; 
       img = BitmapFactory.decodeStream(inputStream);   
      } catch (MalformedURLException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      }  
      return img; 
     } 

     @Override 
     protected void onPostExecute(Bitmap bitmap){ 
      bitmapImgView.setImageBitmap(bitmap); 
     } 
    } 

cevap

17

:

burada benim kodudur. Kodu değiştir.

@Override 
     protected Bitmap doInBackground(String... params) { 
      // TODO Auto-generated method stub 
      String urlStr = params[0]; 
      Bitmap img = null; 

      HttpClient client = new DefaultHttpClient(); 
      HttpGet request = new HttpGet(urlStr); 
      HttpResponse response; 
      try { 
       response = (HttpResponse)client.execute(request);   
       HttpEntity entity = response.getEntity(); 
       BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity); 
       InputStream inputStream = bufferedEntity.getContent(); 
       img = BitmapFactory.decodeStream(inputStream); 
      } catch (ClientProtocolException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      return img; 
     } 
+0

Bu, diğer çözümleri denemekten bir gün sonra benim için çalıştı. – Scutterman

+0

@Scutterman bunu btn tıklama olayını kullanarak nasıl ekleyebilirim –

+0

@johnson AsyncTask'ın sorusu üzerine Simon'ın yaptığı gibi bir sınıf oluşturun. Düğmenin tıklama etkinliğinde, sınıfınızın yeni bir örneğini oluşturun ve onu uygulayın. Android dokümanlar daha fazla bilgiye sahiptir. Http://developer.android.com/reference/android/os/AsyncTask.html – Scutterman

İlgili konular