13

I'am developping an android app that receive an image url from java server, load image and then display it

after receiving the server response I get this error

   java.net.URISyntaxException: Illegal character in scheme at index 0:  http://farm1.static.flickr.com/131/371306796_7e18d505fb_b.jpg

So how to fix this problem?

0

2 Answers 2

36

As you can see there is a space in this url:

" http://farm1.static.flickr.com/131/371306796_7e18d505fb_b.jpg"

So how to fix this problem?

Probably removing the space will fix it.

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

2 Comments

with trim() method maybe? beacuse i can't removing it manually I will try this
@nawara trim() will most probably work in this case, but this is what I call being a doctor who tries to cure the symptoms. If you get more time on it, try to fix the cause (parser? server sending url with space?).
3

The java.net.URI class can help; in the documentation of URL you find

Note, the URI class does perform escaping of its component fields in certain circumstances. The recommended way to manage the encoding and decoding of URLs is to use an URI

Use one of the constructors with more than one argument, like:

URI uri = new URI(
    "http", 
    "http://farm1.static.flickr.com", 
    "/131/371306796_7e18d505fb_b.jpgf",
    null);
URL url = uri.toURL();

the single-argument constructor of URI does NOT escape illegal characters

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.