简体   繁体   English

在Android中获取图像时的System.err

[英]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: 我正在使用Messenger服务从URL异步获取图像,但是LogCat抛出了奇怪的错误消息:

W/System.err(26180): Error reading from ./org/apache/harmony/awt/www/content/image/png.class W / System.err(26180):从./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 W / System.err(26180):从./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"); 我替换了Drawable.createFromStream((((InputStream)new URL(urlString).getContent()),“ name”); with
Drawable.createFromStream((new URL(url)).openConnection().getInputStream(), "name"); Drawable.createFromStream((new URL(url))。openConnection()。getInputStream(),“名称”);

Of course this isn't exactly your code, but I suspect that replacing getContent() with openConnection().getInputStream() would work for you too. 当然,这不完全是您的代码,但是我怀疑用openConnection()。getInputStream()替换getContent()也对您有用。

It's obviously an error in the Apache/Harmony framework. 显然,这是Apache / Harmony框架中的错误。 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. 我想您可能会忽略它,即使您想要也无法在其中更改代码:)对于apache / harmony开发人员来说,这有点像日志记录的东西,您不必在意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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