简体   繁体   中英

System.err when fetching an image in Android

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.

It's obviously an error in the Apache/Harmony framework. I think you may ignore it, you can't change the code there, even if you want :) It's kinda a logging stuff for the apache/harmony developers, you don't have to care about this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM