因此,通常我可以通過查看錯誤日誌來了解發生了什麼。大多數時候,它給了我一個線路號碼,我可以從那裏看出來。Logcat錯誤我不明白
但現在,我迷路了。我不明白我的代碼有問題。
我不知道哪裏可以解決這個錯誤。我不要求任何講義或代碼修正,所以我沒有表現出我的代碼還沒有,我只是想搞清楚這個錯誤的一些技巧:
12-10 17:12:20.359: E/AndroidRuntime(14072): FATAL EXCEPTION: main
12-10 17:12:20.359: E/AndroidRuntime(14072): android.os.NetworkOnMainThreadException
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
12-10 17:12:20.359: E/AndroidRuntime(14072): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
12-10 17:12:20.359: E/AndroidRuntime(14072): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
12-10 17:12:20.359: E/AndroidRuntime(14072): at java.net.InetAddress.getAllByName(InetAddress.java:214)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-10 17:12:20.359: E/AndroidRuntime(14072): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-10 17:12:20.359: E/AndroidRuntime(14072): at com.sencide.AndroidLogin.postLoginData(AndroidLogin.java:101)
12-10 17:12:20.359: E/AndroidRuntime(14072): at com.sencide.AndroidLogin.onClick(AndroidLogin.java:153)
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.view.View.performClick(View.java:4211)
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.view.View$PerformClick.run(View.java:17362)
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.os.Handler.handleCallback(Handler.java:725)
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.os.Handler.dispatchMessage(Handler.java:92)
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.os.Looper.loop(Looper.java:137)
12-10 17:12:20.359: E/AndroidRuntime(14072): at android.app.ActivityThread.main(ActivityThread.java:5227)
12-10 17:12:20.359: E/AndroidRuntime(14072): at java.lang.reflect.Method.invokeNative(Native Method)
12-10 17:12:20.359: E/AndroidRuntime(14072): at java.lang.reflect.Method.invoke(Method.java:511)
12-10 17:12:20.359: E/AndroidRuntime(14072): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
12-10 17:12:20.359: E/AndroidRuntime(14072): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
12-10 17:12:20.359: E/AndroidRuntime(14072): at dalvik.system.NativeStart.main(Native Method)
您可能需要搜索避免出現'NetworkOnMainThreadException'。然後,當您在主/ UI線程上執行網絡操作時,您會發現會發生這種情況。 Post code .. –
[看這個答案](http://stackoverflow.com/questions/16091341/what-is-the-way-to-run-a-new-thread-and-a-ui-thread-in -android/16091615#16091615)將您的網絡操作放入'AsyncTask'中 – codeMagic