Android Network access exception: Android.os.NetworkOnMainThreadException

Source: Internet
Author: User

caused by:android.os.NetworkOnMainThreadException
At Android.os.strictmode$androidblockguardpolicy.onnetwork (Strictmode.java)
At Java.net.InetAddress.lookupHostByName (inetaddress.java:388)
At Java.net.InetAddress.getAllByNameImpl (inetaddress.java:239)
At Java.net.InetAddress.getAllByName (inetaddress.java:214)
At Libcore.net.http.httpconnection.<init> (httpconnection.java:70)
At Libcore.net.http.httpconnection.<init> (httpconnection.java:50)
At Libcore.net.http.httpconnection$address.connect (httpconnection.java:340)
At Libcore.net.http.HttpConnectionPool.get (httpconnectionpool.java:87)
At Libcore.net.http.HttpConnection.connect (httpconnection.java:128)
At Libcore.net.http.HttpEngine.openSocketConnection (httpengine.java:315)
At Libcore.net.http.HttpEngine.connect (httpengine.java:310)
At Libcore.net.http.HttpEngine.sendSocketRequest (httpengine.java:289)
At Libcore.net.http.HttpEngine.sendRequest (httpengine.java:239)

At Libcore.net.http.HttpURLConnectionImpl.connect (httpurlconnectionimpl.java:80)

There is no problem running on 2.3 of the phones, this exception will occur on the phone after 2.3.

After 2.3 Android does not allow access to the network in the main thread, because access to the network is time-consuming operation, if the main thread to access the network, when the network access is slow, the user interface will be suspended animation, resulting in Android not Response, in order to avoid this problem, 2.3 after the limit, Time-consuming operations must be done in a child thread!!!

Android Network access exception: Android.os.NetworkOnMainThreadException

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.