-4
05-08 11:04:12.336: E/AndroidRuntime(678): FATAL EXCEPTION: main

05-08 11:04:12.336: E/AndroidRuntime(678): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android/com.android.Calendar_googleActivity}: android.os.NetworkOnMainThreadException

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.ActivityThread.access$600(ActivityThread.java:123)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.os.Handler.dispatchMessage(Handler.java:99)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.os.Looper.loop(Looper.java:137)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.ActivityThread.main(ActivityThread.java:4424)

05-08 11:04:12.336: E/AndroidRuntime(678):  at java.lang.reflect.Method.invokeNative(Native Method)

05-08 11:04:12.336: E/AndroidRuntime(678):  at java.lang.reflect.Method.invoke(Method.java:511)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)

05-08 11:04:12.336: E/AndroidRuntime(678):  at dalvik.system.NativeStart.main(Native Method)

05-08 11:04:12.336: E/AndroidRuntime(678): Caused by: android.os.NetworkOnMainThreadException

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)

05-08 11:04:12.336: E/AndroidRuntime(678):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)

05-08 11:04:12.336: E/AndroidRuntime(678):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)

05-08 11:04:12.336: E/AndroidRuntime(678):  at java.net.InetAddress.getAllByName(InetAddress.java:220)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.makeSslConnection(HttpsURLConnectionImpl.java:460)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpsURLConnectionImpl$HttpsEngine.connect(HttpsURLConnectionImpl.java:432)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)

05-08 11:04:12.336: E/AndroidRuntime(678):  at libcore.net.http.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:164)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:88)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:814)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.google.api.client.googleapis.json.GoogleJsonResponseException.execute(GoogleJsonResponseException.java:182)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.google.api.client.googleapis.services.GoogleClient.executeUnparsed(GoogleClient.java:115)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.google.api.client.http.json.JsonHttpRequest.executeUnparsed(JsonHttpRequest.java:112)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.google.api.services.calendar.Calendar$CalendarList$List.execute(Calendar.java:510)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.android.Calendar_googleActivity.onAuthToken(Calendar_googleActivity.java:267)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.android.Calendar_googleActivity.gotAccount(Calendar_googleActivity.java:118)

05-08 11:04:12.336: E/AndroidRuntime(678):  at com.android.Calendar_googleActivity.onCreate(Calendar_googleActivity.java:108)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.Activity.performCreate(Activity.java:4465)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)

05-08 11:04:12.336: E/AndroidRuntime(678):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)

05-08 11:04:12.336: E/AndroidRuntime(678):  ... 11 more
4

1 回答 1

2
 Caused by: android.os.NetworkOnMainThreadException

您一直被警告不要在 UI 线程上进行联网,因为如果网络操作延迟,这可能会导致 UI 滞后和应用程序无响应错误。

在最近的版本中,您现在实际上被禁止 - 由于上面的主动错误 - 试图“摆脱它”

所以让你的网络使用脱离 UI 线程,你应该已经准备好了。我们不需要在这里讨论如何做到这一点 - 它在文档和以前的问题中有很好的介绍。

于 2012-05-08T04:37:44.990 回答