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

10-08 14:25:38.694 3090-3090/? E/NET: Throwable:
android.os.NetworkOnMainThreadException
at android.os.StrictMode1.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.iMethodAndArgsCaller.run(ZygoteInit.java:880)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:770)

你可能感兴趣的:(网络请求不能放在主线程执行,不然可能发生以下报错)