Question

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.

Was it helpful?

Solution

I used

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

i replaced all the spaces by %20

and its working for me ..

Thanks everybody for their responses

OTHER TIPS

Please help by telling what I am doing wrong.

I think that the problem is that you are calling the URL constructor with an invalid URL string. Indeed, the exception message implies that the URL string starts with "9:". (The 'protocol' component is the sequence of characters before the first colon character of the URL.)

This doesn't make a lot of sense if the URL string really is:

"http://www.elifeshopping.com/images/stories/virtuemart/product/thumbnail (2).jpg"

so I'd infer that it is ... in fact ... something else. Print it out before you call the URL constructor to find out what it really is.

(You should also %-escape the space characters in the URL's path ... but I doubt that will fix this particular exception incarnation.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top