Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SkImageDecoder::Factory returned null Error

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);
        }
    }
like image 803
Simon Avatar asked May 09 '14 08:05

Simon


1 Answers

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;
        }
like image 168
Simon Avatar answered Nov 14 '22 15:11

Simon