Android HttpClient : NetworkOnMainThreadException

后端 未结 4 1017
离开以前
离开以前 2020-11-29 12:45

I have some code below:

protected void testConnection(String url) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new Htt         


        
4条回答
  •  情深已故
    2020-11-29 13:35

    I you run your code in android 2.x and its lower version, i think this code will run perfectly. But if you run this in 3.x and it's upper version then you get an Exception. The problem is the you need to call the web service from your worker thread(AsyncTask<>) . You can not call the web service from the main thread.

提交回复
热议问题