1

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.

3
  • Where do you get the url from. Check that your variable url input string starts with either http:// or https:// print the url string in the exception Commented May 3, 2012 at 13:27
  • i get the url in webservice nd it starts with http only Commented May 3, 2012 at 13:28
  • You should open the URL connection Commented May 3, 2012 at 13:44

3 Answers 3

6

I used

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

i replaced all the spaces by %20

and its working for me ..

Thanks everybody for their responses

Sign up to request clarification or add additional context in comments.

1 Comment

works for me, I checked in browser it is showing in Image but when I checked in app it shows that Malformed exception, So I added this small code It works fine, It is not showing error. Thanks @Shruti
2

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

2 Comments

i didn't got this (exception message implies that the URL string starts with "9:". (The 'protocol' component is the sequence of characters before the first colon character.)) ... do i need to edit http ?
@Shruti - I'm saying that that string is not the one that you are passing to the URL constructor.
0

Change your url to http://www.elifeshopping.com/images/stories/virtuemart/product/thumbnail%20%282%29.jpg

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.