I’m using a messenger service to asynchronously fetch an image from a URL but LogCat is throwing a strange error message:
W/System.err(26180): Error reading from ./org/apache/harmony/awt/www/content/image/png.class
– or –
W/System.err(26180): Error reading from ./org/apache/harmony/awt/www/content/image/jpeg.class
The funny thing is that everything works. The image is successfully being decoded into a Bitmap on the first try.
Here is my code:
@Override
public void onHandleIntent(Intent i) {
int position = (Integer)i.getExtras().get(EXTRA_POSITION);
String imageUrl = (String)i.getExtras().get(EXTRA_URL);
Messenger messenger = (Messenger)i.getExtras().get(EXTRA_MESSENGER);
Message msg = Message.obtain();
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
msg.arg1 = Activity.RESULT_OK;
msg.arg2 = position;
msg.obj = bitmap;
} catch(Exception e) {
Log.e("RSSForHC", "Exception getting image", e);
msg.arg1 = Activity.RESULT_CANCELED;
msg.obj = e;
}
try {
messenger.send(msg);
} catch (Exception e) {
Log.w("RSSForHC","Exception sending results to activity", e);
}
}
The error is definently being thrown on this line:
bitmap = BitmapFactory.decodeStream((InputStream)new URL(imageUrl).getContent());
Since everything works my question is whether or not it’s acceptable to ignore this error? Does anyone know why this error is being thrown and how I can possibly correct it or handle it?
This worked for me to get rid of those messages. Of course Michael may still be right that ignoring them is okay.
I replaced
Drawable.createFromStream(((InputStream)new URL(urlString).getContent()), “name”);
with
Drawable.createFromStream((new URL(url)).openConnection().getInputStream(), “name”);
Of course this isn’t exactly your code, but I suspect that replacing getContent() with openConnection().getInputStream() would work for you too.