【发布时间】:2012-05-03 13:20:02
【问题描述】:
我正在尝试使用 BitmapFactory 从 url (http://www.elifeshopping.com/images/stories/virtuemart/product/thumbnail (2).jpg) 在我的 android 应用程序中加载图像,代码如下:
try {
// ImageView i = (ImageView)findViewById(R.id.image);
bitmap = BitmapFactory.decodeStream((InputStream) new URL(url)
.getContent());
i.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
我明白了
05-03 15:57:13.156: W/System.err(1086): java.net.MalformedURLException: Protocol not found: 9
05-03 15:57:13.167: W/System.err(1086): at java.net.URL.<init>(URL.java:273)
05-03 15:57:13.167: W/System.err(1086):
at java.net.URL.<init>(URL.java:157).
请告诉我我做错了什么。
【问题讨论】:
-
你从哪里得到网址。检查您的变量 url 输入字符串是否以 http:// 或 https:// 开头打印异常中的 url 字符串
-
我在 web 服务中获取了 url,它仅以 http 开头
-
你应该打开 URL 连接
标签: java android malformedurlexception