How to resolve java.net.MalformedURLException: Protocol not found: 9 in android

Shruti picture Shruti · May 3, 2012 · Viewed 23.1k times · Source

I am trying to load images in my android application from a url (http://www.elifeshopping.com/images/stories/virtuemart/product/thumbnail (2).jpg) using BitmapFactory the code is below :

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();
        }

here i get

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).

Please help by telling what I am doing wrong.

Answer

Shruti picture Shruti · May 11, 2012

I used

productImgUrl = productImgUrl.replaceAll(" ", "%20");

i replaced all the spaces by %20

and its working for me ..

Thanks everybody for their responses