微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将图像放在ListView上时,“ resolveUri在错误的位图uri上失败”

如何解决将图像放在ListView上时,“ resolveUri在错误的位图uri上失败”

我已经解决了这个问题。我正在使用代码解决问题。

这里的“路径”是可以使用的本地文件系统路径:

public static String loadImageFromWebOperations(String url, String path) {
    try {
        InputStream is = (InputStream) new URL(url).getContent();

        System.out.println(path);
        File f = new File(path);

        f.createNewFile();
        FileOutputStream fos = new FileOutputStream(f);
        try {

            byte[] b = new byte[100];
            int l = 0;
            while ((l = is.read(b)) != -1)
                fos.write(b, 0, l);

        } catch (Exception e) {

        }

        return f.getAbsolutePath();
    } catch (Exception e) {
        System.out.println("Exc=" + e);
        return null;

    }
}

希望这可以帮助 :)。

解决方法

嘿,我是android新手,我有一个小问题。我正在尝试将列表视图与图像一起通过URL加载。到目前为止,该方法仍然有效,但是图像不会显示。logcat这样说:

02-23 19:20:48.447: INFO/System.out(833): resolveUri failed on bad bitmap uri: android.graphics.drawable.BitmapDrawable@405359b0

它显然找不到我的形象,但我不知道为什么。使用R.drawable.icon可以。谁能帮我吗?这是我的消息来源:

public class Main extends Activity {
        private ListView lv_main;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        lv_main = (ListView) findViewById(R.id.listviewmain);

        ArrayList<HashMap<String,String>> listItem = new ArrayList<HashMap<String,String>>();

        HashMap<String,String> map;

        map = new HashMap<String,String>();
        map.put("title","a title goes here");
        map.put("details","details blaa");
        map.put("cover",String.valueOf(Main.this.LoadImageFromWebOperations("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"));
        //THIS WORKS FINE: map.put("cover",String.valueOf(R.drawable.icon));
        listItem.add(map);

        map = new HashMap<String,"2nd title");
        map.put("details","more details");
        map.put("cover",String.valueOf(Main.this.LoadImageFromWebOperations("http://www.google.com/images/srpr/nav_logo37.png"));
        //THIS WORKS FINE: map.put("cover",String.valueOf(R.drawable.icon));
        listItem.add(map);

        SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(),listItem,R.layout.listviewitem,new String[] {"cover","title","details"},new int[] {R.id.cover,R.id.title,R.id.details});

        lv_main.setAdapter(mSchedule);
     }

    public Drawable LoadImageFromWebOperations(String url) {
        try
        {
                InputStream is = (InputStream) new URL(url).getContent();
                Drawable d = Drawable.createFromStream(is,"src name");
                return d;
        }catch (Exception e) {
                System.out.println("Exc="+e);
                return null;
        }
    }
}

提前致谢。抢

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。