Android SkImageDecoder::Factory返回null错误



我试图从URL加载图像到ImageView,但错误发生:SkImageDecoder:工厂返回null。我该怎么修理它?

下面是我的代码:
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);
        }
    }

解决。将代码修改为:

@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;
        }

最新更新