
嘿,
我是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, String>(); map.put("Title", "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; } }}提前致谢.
抢
解决方法:
我已经解决了这个问题.
我正在使用代码来解决问题.
这里’Path’是一个可以使用的本地文件系统路径:Environment.getExternalStorageDirectory().getabsolutePath()
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 – 将图像放在ListView上时,“resolveUri在坏位图uri上失败”全部内容,希望文章能够帮你解决android – 将图像放在ListView上时,“resolveUri在坏位图uri上失败”所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)