java - 如何解决 java.net.MalformedURLException : Protocol not found: 9 in android

标签 java android malformedurlexception

我正在尝试使用 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/

相关文章:

java - RingtoneManager.setActualDefaultRingtoneUri() 在 API 23 中工作吗?

java - 将 Java 1.5 兼容代码转换为 Java 1.4

android - React Native,Redux store 最小化后

android - OAuth 2.0 Android 重定向_uri 问题

java - MalformedURLException 错误

java - 具有可变数量对象的配置文件

java - 为元素创建 XPATH - Selenium

java - LibGDX 简单的二维 block 图渲染

android - 无法在 View 上检测到触摸事件并在父 View 上检测到点击事件

java - BigClip 的问题