我使用php和json請求將數據從android插入到mysql。當事件觸發時,它會在logcat中發出異常。我與你分享我的clogcat所以你可以有更好的外觀和正在發生的事情的想法,這裏是我的logcat:從android插入到php
三月一十日至7日:55:13.073:E/AndroidRuntime(1665):致命異常:main 10-07 03:55:13.073:E/AndroidRuntime(1665): android.os.NetworkOnMainThreadException 10-07 03:55:13.073: E/AndroidRuntime(1665):at android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1133) 10-07 03:55:13.073:E/AndroidRuntime(1665):at java.net.InetAddress.lookupHostByName(InetAddress.java:385)10-07 03:55 :13.073:E/AndroidRuntime(1665):在 java.net.InetAddress.ge tAllByNameImpl(InetAddress.java:236)10-07 03:55:13.073:E/AndroidRuntime(1665):at java.net.InetAddress.getAllByName(InetAddress.java:214)10-07 03:55:13.073 :E/AndroidRuntime(1665):在 org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137) 3月10日至7日:55:13.073:E/AndroidRuntime(1665):在 組織.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164) 10-07 03:55:13.073:E/AndroidRuntime(1665):at org.apache.http.impl.conn.AbstractPooledConnAdapter。 open(AbstractPooledConnAdapter.java:119) 10-07 03:55:13.073:E/AndroidRuntime(1665):at org.apache.http.impl.client.DefaultRequestDirector.execute(Defaul tRequestDirector.java:360) 10-07 03:55:13.073:E/AndroidRuntime(1665):at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 10-07 03 :55/13.073:E/AndroidRuntime(1665):at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 10-07 03:55:13.073:E/AndroidRuntime(1665) :at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 10-07 03:55:13.073:E/AndroidRuntime(1665):at com.example.receiptorganizer.Registration $ 1 .insert(Registration.java:78) 10-07 03:55:13.073:E/AndroidRuntime(1665):at com.example.receiptorganizer.Registration $ 1.onClick(Registration.java:58) 10-07 03:55:13.073:E/AndroidRuntime(1665):at android.view.View.performClick(View.java:4240)10-07 03:55:13.073: E/AndroidRuntime(1665):在 android.view.View $ PerformClick.run(View.java:17721)10-07 03:55:13.073:E/AndroidRuntime(1665):at android.os.Handler.handleCallback(Handler.java:730 )10-07 03:55:13.073:E/AndroidRuntime(1665):at android.os.Handler.dispatchMessage(Handler.java:92)10-07 03:55:13.073:E/AndroidRuntime(1665) :at android.os.Looper.loop(Looper.java:137)10-07 03:55:13.073: E/AndroidRuntime(1665):at android.app.ActivityThread.main(ActivityThread.java:5103) 10-07 03:55:13.07 3:E/AndroidRuntime(1665):at java.lang.reflect.Method.invokeNative(Native Method)10-07 03:55:13.073:E/AndroidRuntime(1665):at java.lang.reflect.Method .invoke(Method.java:525)10-07 03:55:13.073: E/AndroidRuntime(1665):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 10 -07 03:55:13.073:E/AndroidRuntime(1665):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)10-07 03:55:13。073:E/AndroidRuntime(1665):在 dalvik.system.NativeStart.main(本機方法)
我想你應該在請別人解決你的問題之前花更多的精力。只需將'android.os.NetworkOnMainThreadException'粘貼到Google就可以爲您提供答案。要了解倒票,請參閱[幫助](http://stackoverflow.com/help)頁面。 :) – Qben