我的應用程序工作在Android版本2.3.3沒有任何問題,但是當我在Galaxy S5(4和更多)testdc它,它不起作用。logCat錯誤當我按下按鈕
這裏是logcat的錯誤輸出:
10-17 04:18:10.265: W/dalvikvm(26757): threadid=1: thread exiting with uncaught exception (group=0x41a95c08)
10-17 04:18:10.265: E/AndroidRuntime(26757): FATAL EXCEPTION: main
10-17 04:18:10.265: E/AndroidRuntime(26757): Process: com.androidexample.httppostexample, PID: 26757
10-17 04:18:10.265: E/AndroidRuntime(26757): android.os.NetworkOnMainThreadException
10-17 04:18:10.265: E/AndroidRuntime(26757): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1166)
10-17 04:18:10.265: E/AndroidRuntime(26757): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
10-17 04:18:10.265: E/AndroidRuntime(26757): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
10-17 04:18:10.265: E/AndroidRuntime(26757): at java.net.InetAddress.getAllByName(InetAddress.java:214)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:167)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:125)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.client.DefaultRequestDirector.executeOriginal(DefaultRequestDirector.java:1227)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:677)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
10-17 04:18:10.265: E/AndroidRuntime(26757): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
10-17 04:18:10.265: E/AndroidRuntime(26757): at com.androidexample.httppostexample.HttpPostExample$2.onClick(HttpPostExample.java:157)
10-17 04:18:10.265: E/AndroidRuntime(26757): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
10-17 04:18:10.265: E/AndroidRuntime(26757): at android.os.Handler.dispatchMessage(Handler.java:102)
10-17 04:18:10.265: E/AndroidRuntime(26757): at android.os.Looper.loop(Looper.java:136)
10-17 04:18:10.265: E/AndroidRuntime(26757): at android.app.ActivityThread.main(ActivityThread.java:5586)
10-17 04:18:10.265: E/AndroidRuntime(26757): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 04:18:10.265: E/AndroidRuntime(26757): at java.lang.reflect.Method.invoke(Method.java:515)
10-17 04:18:10.265: E/AndroidRuntime(26757): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
10-17 04:18:10.265: E/AndroidRuntime(26757): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
10-17 04:18:10.265: E/AndroidRuntime(26757): at dalvik.system.NativeStart.main(Native Method)
這是我AndroidManifest
誰能幫助我解決這個問題?
嗨大腸桿菌。你可以檢查我的代碼嗎? –
如果你正在實施糟糕的解決方案(這也是你不應該這樣做的)。所有你需要做的就是把這兩行放入onCreate函數並導入合適的庫(Android Studio應該爲你做) – Colin