Skip to content
Advertisement

Why does url with space gives me MalformedURLException? [closed]

I work with GoogleBook API, when i type one word on EditText, URL link works well for example: I type prince and the app doesn’t crash, but when i type the prince it crashes and give me MalformedURLException : no protocol.

I have searched on Stackoverflow, then i found 2 solutions and nothing solved my problem.

  • First Solution:
JavaScript

returned value: https://www.googleapis.com/books/v1/volumes?download=DOWNLOAD_UNDEFINED&filter=FILTER_UNDEFINED&libraryRestrict=LIBRARY_RESTRICT_UNDEFINED&maxResults=20&orderBy=relevance&printType=ALL&q=the%20prince&key=AIzaSyCJmeSLPw147mRSnc2nZNgPSbebtH-RxDc (there is %20 between the and prince)

The first If statement above that check if the string contains whitespace didn’t solve my problem, i get the same exception.

  • Second Solution:
JavaScript

returned value: https://www.googleapis.com/books/v1/volumes?download=DOWNLOAD_UNDEFINED&filter=FILTER_UNDEFINED&libraryRestrict=LIBRARY_RESTRICT_UNDEFINED&maxResults=20&orderBy=relevance&printType=ALL&q=the+prince&key=AIzaSyCJmeSLPw147mRSnc2nZNgPSbebtH-RxDc (there is + between the and prince)

I pass that value to this method: (The exception occur here)

JavaScript

Important Update: I typed another word (this: the price) and the app worked well, the problem with some words

Thanks in advance

Advertisement

Answer

Thanks to everyone, the problem was in StringBuilder itself at makeURL(), i replaced it with String then everything worked without any exceptions. makeURL() after editing:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement