Strange NetworkOnMainThreadException in Android app?

后端 未结 3 768
眼角桃花
眼角桃花 2020-12-11 10:42

The idea is to start a chat. So I have this properties in my class:

private MulticastSocket so;
private EditText messageBoard;
private InetAddress serverAddr         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-11 11:39

    this line:

    Caused by: android.os.NetworkOnMainThreadException
    

    Tells you what is going on.

    You are attempting to access a network function on the Main(UI) thread. starting with Honeycomb the system raises an Exception when you do this.

    To fix you just need to move any thing that is touching the network to its own thread.

提交回复
热议问题