T. Falcão T. Falcão - 5 months ago 129
Java Question

SkImageDecoder::Factory returned null and URL is correct

I'm trying to put an Image from a URL in a ImageView, but I keep getting the "SkImageDecoder::Factory returned null" error.

Here's my code:

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

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

protected Bitmap doInBackground(String... urls) {
String myUrl= urls[0];

Bitmap myBmp= null;
try {
InputStream in = new URL(urldisplay).openStream();
myBmp= BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return myBmp;
}

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


EDIT: logcat when the app crashes after getting the first image
logcat

public class customAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> values;

static class ViewHolder {

private TextView textViewName;
private TextView textViewType;
private ImageView imageView;
}

public customAdapter(Context context, ArrayList<String> values) {
super(context, R.layout.list_member, values);
this.context = context;
this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder mViewHolder = null;
if (convertView == null) {
mViewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_member, parent, false);
mViewHolder.textViewName = (TextView) convertView.findViewById(R.id.name);
mViewHolder.textViewType = (TextView) convertView.findViewById(R.id.type);
mViewHolder.imageView = (ImageView) convertView.findViewById(R.id.image);

convertView.setTag(mViewHolder);
}
else {
mViewHolder = (ViewHolder) convertView.getTag();
}
String s = values.get(position);
StringTokenizer st = new StringTokenizer(s, "*");
String name = st.nextToken();
String url_photo = st.nextToken();
String type = st.nextToken();
if (type.equals("CHILD")) {
String count_dev = st.nextToken();
mViewHolder.textViewType.setText(count_dev);
}
else {
mViewHolder.textViewType.setText(type);
}
mViewHolder.textViewName.setText(name);
new DownloadImageTask(mViewHolder.imageView).execute(url_photo);
return convertView;
}

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

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

protected Bitmap doInBackground(String... urls) {
// TODO Auto-generated method stub
String urlStr = urls[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) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return img;
}

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


As requested, this is the full code for this class

Answer

Try to add this code in your background method:

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