Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetworkOnMainThreadException with newer Android versions #1

Open
ened opened this issue Dec 5, 2012 · 3 comments
Open

NetworkOnMainThreadException with newer Android versions #1

ened opened this issue Dec 5, 2012 · 3 comments

Comments

@ened
Copy link

ened commented Dec 5, 2012

12-05 13:02:04.201: ERROR/com.app.service.PushService(5696): MqttException
        com.ibm.mqtt.MqttException
        at com.ibm.mqtt.MqttBaseClient.doConnect(Unknown Source)
        at com.ibm.mqtt.MqttBaseClient.connect(Unknown Source)
        at com.ibm.mqtt.MqttClient.connect(Unknown Source)
        at com.ibm.mqtt.MqttClient.connect(Unknown Source)
        at com.app.service.PushService$MQTTConnection.<init>(PushService.java:446)
        at com.app.service.PushService.connect(PushService.java:284)
        at com.app.service.PushService.reconnectIfNecessary(PushService.java:378)
        at com.app.service.PushService.onStartCommand(PushService.java:191)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2490)
        at android.app.ActivityThread.access$1900(ActivityThread.java:130)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1292)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.app.ActivityThread.main(ActivityThread.java:4745)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.os.NetworkOnMainThreadException
        at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
        at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
        at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
        at java.net.InetAddress.getByName(InetAddress.java:289)
        at java.net.InetSocketAddress.<init>(InetSocketAddress.java:105)
        at java.net.InetSocketAddress.<init>(InetSocketAddress.java:90)
        at com.ibm.mqtt.j2se.MqttJava14NetSocket.<init>(Unknown Source)
        at com.ibm.mqtt.j2se.MqttJavaNetSocket.setConnection(Unknown Source)
        at com.ibm.mqtt.Mqtt.tcpipConnect(Unknown Source)

Seems to happen on JB+ now.

@nocb
Copy link

nocb commented Apr 18, 2013

same to you

@lovebing
Copy link

To solve this problem, you need to use a new thread to connect mqtt server

@hexige
Copy link

hexige commented Oct 24, 2017

In ur pushService,start a new thread to do sth about mqtt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants