Malformedurlexception Solution in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.