android.os.NetworkOnMainThreadException for webservice (ksoap)

后端 未结 3 605
不知归路
不知归路 2021-01-02 12:47

I am new to android programming and trying to use webservice in this sample program:

I use Android 4.1 and my IDE is Eclipse Juno. I think the programming part is ok

3条回答
  •  渐次进展
    2021-01-02 13:23

    You can't do Network operations on the main thread. Checkout : http://developer.android.com/reference/android/os/AsyncTask.html

    for painless background threading :)

    EDIT: Since I am still getting up-votes for this answer even though it's several years old I would no longer suggest using AsyncTask. It has many known problems which are described here (http://blog.danlew.net/2014/06/21/the-hidden-pitfalls-of-asynctask/). Instead I would urge you to use Retrofit or one of the other nice http clients which handles the threading for you.

提交回复
热议问题