我正在尝试使用 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).
请告诉我做错了什么。
最佳答案
我用过
productImgUrl = productImgUrl.replaceAll(" ", "%20");
我用 %20
替换了所有空格
它对我有用..
谢谢大家的回复
关于java - 如何解决 java.net.MalformedURLException : Protocol not found: 9 in android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10432271/