Android SkImageDecoder::Factory returned null Error

16,723

Solved. Change the code to this.

@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;
        }
Share:
16,723
Simon
Author by

Simon

Updated on July 08, 2022

Comments

  • Simon
    Simon almost 2 years

    I'm trying to load an image from URL to an ImageView but the error occurs: SkImageDecoder::Factory returned null. How can I fix it?

    here is my code :

    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);
            }
        }
    
  • Scutterman
    Scutterman almost 10 years
    This worked for me after a whole day of trying other solutions.
  • Scutterman
    Scutterman over 9 years
    @johnson Just create a class that extends AsyncTask like Simon has in his question. In the button's click event, create a new instance of your class and execute it. The Android docs have more information developer.android.com/reference/android/os/AsyncTask.html
  • Droid Chris
    Droid Chris about 9 years
    You sir rock! This works great for getting facebook user profile images etc!
  • Maveňツ
    Maveňツ almost 7 years
    Its working perfect but I don't know the exact reason of issue & resolution.