网络请求不能放在主线程执行,不然可能发生以下报错

2018-10-08  本文已影响52人  在下陈小村

10-08 14:25:38.694 3090-3090/? E/NET: Throwable:
android.os.NetworkOnMainThreadException
at android.os.StrictModeAndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303) at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:86) at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74) at java.net.InetAddress.getAllByName(InetAddress.java:752) at com.android.okhttp.internal.Network1.resolveInetAddresses(Network.java:29)
at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:187)
at com.android.okhttp.internal.http.RouteSelector.nextProxy(RouteSelector.java:156)
at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:98)
at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:346)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:329)
at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:247)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:457)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:126)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:257)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:218)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java)
at com.xiaomi.mistatistic.sdk.controller.l.a(SourceFile:181)
at com.xiaomi.mistatistic.sdk.controller.l.a(SourceFile:421)
at com.xiaomi.mistatistic.sdk.controller.i.a(SourceFile:299)
at com.xiaomi.mistatistic.sdk.controller.i.a(SourceFile:279)
at com.xiaomi.mistatistic.sdk.controller.i.a(SourceFile:30)
at com.xiaomi.mistatistic.sdk.controller.i2.handleMessage(SourceFile:109) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:163) at android.app.ActivityThread.main(ActivityThread.java:6360) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInitMethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

上一篇下一篇

猜你喜欢

热点阅读