When we need to create a URL object, we can use the following methods:
URL url = new URL (urlstring);
Where urlstring represents our link address, there are possible reasons for the malformedurlexception exception:
1.urlString corresponding link address needs to be added in the previous "HTTP//", usually we do not need to add "http//" in the address bar of the browser, because the browser uses the HTTP protocol by default, the browser will help us add "http/ ", and when we create the URL object, it is not added automatically, so we need to add"/http "
2. When the address of the URL is related to Chinese, it is necessary to format the URL and convert the urlstring, only the Chinese can be converted in a single conversion format, the entire URL can not be converted, Because other normal characters may be converted to incorrect URL characters:
Key code for conversion:
URLString = Urlencoder.encode (urlstring, "UTF8"); This is only for illustrative purposes, and it is not considered to be a separate translation of the Chinese.
Malformedurlexception Solution in Android