2012-10-23 159 views
0

我嘗試從我的Android程序連接到我的C#WebService。當嘗試連接Web服務時出現錯誤

當我連接通過模擬器其工作出色。

但是當我連接通過手機我得到錯誤。

我禁用FireWall並從瀏覽器中的手機中查看web服務。

,我得到了錯誤:

10-23 20:02:14.697: W/System.err(25237): android.os.NetworkOnMainThreadException 
10-23 20:02:14.697: W/System.err(25237): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 
10-23 20:02:14.697: W/System.err(25237): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84) 
10-23 20:02:14.697: W/System.err(25237): at libcore.io.IoBridge.connectErrno(IoBridge.java:138) 
10-23 20:02:14.697: W/System.err(25237): at libcore.io.IoBridge.connect(IoBridge.java:112) 
10-23 20:02:14.697: W/System.err(25237): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) 
10-23 20:02:14.702: W/System.err(25237): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459) 
10-23 20:02:14.702: W/System.err(25237): at java.net.Socket.connect(Socket.java:842) 
10-23 20:02:14.702: W/System.err(25237): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77) 
10-23 20:02:14.702: W/System.err(25237): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 
10-23 20:02:14.702: W/System.err(25237): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351) 
10-23 20:02:14.702: W/System.err(25237): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 
10-23 20:02:14.702: W/System.err(25237): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 
10-23 20:02:14.702: W/System.err(25237): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 
10-23 20:02:14.707: W/System.err(25237): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 
10-23 20:02:14.707: W/System.err(25237): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 
10-23 20:02:14.707: W/System.err(25237): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 
10-23 20:02:14.707: W/System.err(25237): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 
10-23 20:02:14.707: W/System.err(25237): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76) 
10-23 20:02:14.707: W/System.err(25237): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:153) 
10-23 20:02:14.707: W/System.err(25237): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95) 
10-23 20:02:14.707: W/System.err(25237): at com.example.eitanws_exmp.WS.HelloWorld(WS.java:198) 
10-23 20:02:14.707: W/System.err(25237): at com.example.eitanws_exmp.MainActivity.GetArray_Click(MainActivity.java:53) 
10-23 20:02:14.712: W/System.err(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.712: W/System.err(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.712: W/System.err(25237): at android.view.View$1.onClick(View.java:3064) 
10-23 20:02:14.712: W/System.err(25237): at android.view.View.performClick(View.java:3591) 
10-23 20:02:14.712: W/System.err(25237): at android.view.View$PerformClick.run(View.java:14263) 
10-23 20:02:14.712: W/System.err(25237): at android.os.Handler.handleCallback(Handler.java:605) 
10-23 20:02:14.712: W/System.err(25237): at android.os.Handler.dispatchMessage(Handler.java:92) 
10-23 20:02:14.712: W/System.err(25237): at android.os.Looper.loop(Looper.java:137) 
10-23 20:02:14.717: W/System.err(25237): at android.app.ActivityThread.main(ActivityThread.java:4507) 
10-23 20:02:14.717: W/System.err(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.717: W/System.err(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.717: W/System.err(25237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
10-23 20:02:14.717: W/System.err(25237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
10-23 20:02:14.717: W/System.err(25237): at dalvik.system.NativeStart.main(Native Method) 
10-23 20:02:14.722: W/System.err(25237): android.os.NetworkOnMainThreadException 
10-23 20:02:14.727: W/System.err(25237): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 
10-23 20:02:14.727: W/System.err(25237): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84) 
10-23 20:02:14.727: W/System.err(25237): at libcore.io.IoBridge.connectErrno(IoBridge.java:138) 
10-23 20:02:14.727: W/System.err(25237): at libcore.io.IoBridge.connect(IoBridge.java:112) 
10-23 20:02:14.727: W/System.err(25237): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) 
10-23 20:02:14.727: W/System.err(25237): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459) 
10-23 20:02:14.732: W/System.err(25237): at java.net.Socket.connect(Socket.java:842) 
10-23 20:02:14.732: W/System.err(25237): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77) 
10-23 20:02:14.732: W/System.err(25237): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 
10-23 20:02:14.732: W/System.err(25237): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351) 
10-23 20:02:14.732: W/System.err(25237): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 
10-23 20:02:14.732: W/System.err(25237): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 
10-23 20:02:14.737: W/System.err(25237): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 
10-23 20:02:14.737: W/System.err(25237): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 
10-23 20:02:14.737: W/System.err(25237): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 
10-23 20:02:14.737: W/System.err(25237): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 
10-23 20:02:14.737: W/System.err(25237): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 
10-23 20:02:14.737: W/System.err(25237): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76) 
10-23 20:02:14.737: W/System.err(25237): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:153) 
10-23 20:02:14.737: W/System.err(25237): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95) 
10-23 20:02:14.737: W/System.err(25237): at com.example.eitanws_exmp.WS.WebServiceCallExampleGetArray(WS.java:88) 
10-23 20:02:14.737: W/System.err(25237): at com.example.eitanws_exmp.MainActivity.GetArray_Click(MainActivity.java:54) 
10-23 20:02:14.742: W/System.err(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.747: W/System.err(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.752: W/System.err(25237): at android.view.View$1.onClick(View.java:3064) 
10-23 20:02:14.752: W/System.err(25237): at android.view.View.performClick(View.java:3591) 
10-23 20:02:14.752: W/System.err(25237): at android.view.View$PerformClick.run(View.java:14263) 
10-23 20:02:14.752: W/System.err(25237): at android.os.Handler.handleCallback(Handler.java:605) 
10-23 20:02:14.752: W/System.err(25237): at android.os.Handler.dispatchMessage(Handler.java:92) 
10-23 20:02:14.752: W/System.err(25237): at android.os.Looper.loop(Looper.java:137) 
10-23 20:02:14.752: W/System.err(25237): at android.app.ActivityThread.main(ActivityThread.java:4507) 
10-23 20:02:14.752: W/System.err(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.752: W/System.err(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.752: W/System.err(25237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
10-23 20:02:14.752: W/System.err(25237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
10-23 20:02:14.757: W/System.err(25237): at dalvik.system.NativeStart.main(Native Method) 
10-23 20:02:14.757: W/System.err(25237): android.os.NetworkOnMainThreadException 
10-23 20:02:14.762: W/System.err(25237): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 
10-23 20:02:14.762: W/System.err(25237): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84) 
10-23 20:02:14.762: W/System.err(25237): at libcore.io.IoBridge.connectErrno(IoBridge.java:138) 
10-23 20:02:14.762: W/System.err(25237): at libcore.io.IoBridge.connect(IoBridge.java:112) 
10-23 20:02:14.762: W/System.err(25237): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) 
10-23 20:02:14.762: W/System.err(25237): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459) 
10-23 20:02:14.762: W/System.err(25237): at java.net.Socket.connect(Socket.java:842) 
10-23 20:02:14.762: W/System.err(25237): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:77) 
10-23 20:02:14.762: W/System.err(25237): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 
10-23 20:02:14.762: W/System.err(25237): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351) 
10-23 20:02:14.762: W/System.err(25237): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 
10-23 20:02:14.762: W/System.err(25237): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 
10-23 20:02:14.762: W/System.err(25237): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 
10-23 20:02:14.767: W/System.err(25237): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 
10-23 20:02:14.767: W/System.err(25237): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 
10-23 20:02:14.767: W/System.err(25237): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 
10-23 20:02:14.767: W/System.err(25237): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 
10-23 20:02:14.767: W/System.err(25237): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76) 
10-23 20:02:14.767: W/System.err(25237): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:153) 
10-23 20:02:14.767: W/System.err(25237): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95) 
10-23 20:02:14.767: W/System.err(25237): at com.example.eitanws_exmp.WS.WebServiceCallExampleGetArray(WS.java:88) 
10-23 20:02:14.767: W/System.err(25237): at com.example.eitanws_exmp.MainActivity.GetArray_Click(MainActivity.java:56) 
10-23 20:02:14.767: W/System.err(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.767: W/System.err(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.767: W/System.err(25237): at android.view.View$1.onClick(View.java:3064) 
10-23 20:02:14.767: W/System.err(25237): at android.view.View.performClick(View.java:3591) 
10-23 20:02:14.767: W/System.err(25237): at android.view.View$PerformClick.run(View.java:14263) 
10-23 20:02:14.772: W/System.err(25237): at android.os.Handler.handleCallback(Handler.java:605) 
10-23 20:02:14.772: W/System.err(25237): at android.os.Handler.dispatchMessage(Handler.java:92) 
10-23 20:02:14.772: W/System.err(25237): at android.os.Looper.loop(Looper.java:137) 
10-23 20:02:14.772: W/System.err(25237): at android.app.ActivityThread.main(ActivityThread.java:4507) 
10-23 20:02:14.772: W/System.err(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.772: W/System.err(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.772: W/System.err(25237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
10-23 20:02:14.772: W/System.err(25237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
10-23 20:02:14.772: W/System.err(25237): at dalvik.system.NativeStart.main(Native Method) 
10-23 20:02:14.772: D/AndroidRuntime(25237): Shutting down VM 
10-23 20:02:14.772: W/dalvikvm(25237): threadid=1: thread exiting with uncaught exception (group=0x40c511f8) 
10-23 20:02:14.782: E/AndroidRuntime(25237): FATAL EXCEPTION: main 
10-23 20:02:14.782: E/AndroidRuntime(25237): java.lang.IllegalStateException: Could not execute method of the activity 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.view.View$1.onClick(View.java:3069) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.view.View.performClick(View.java:3591) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.view.View$PerformClick.run(View.java:14263) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.os.Handler.handleCallback(Handler.java:605) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.os.Handler.dispatchMessage(Handler.java:92) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.os.Looper.loop(Looper.java:137) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.app.ActivityThread.main(ActivityThread.java:4507) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at dalvik.system.NativeStart.main(Native Method) 
10-23 20:02:14.782: E/AndroidRuntime(25237): Caused by: java.lang.reflect.InvocationTargetException 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.lang.reflect.Method.invokeNative(Native Method) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.lang.reflect.Method.invoke(Method.java:511) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at android.view.View$1.onClick(View.java:3064) 
10-23 20:02:14.782: E/AndroidRuntime(25237): ... 11 more 
10-23 20:02:14.782: E/AndroidRuntime(25237): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 4, size is 0 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.util.ArrayList.get(ArrayList.java:304) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at com.example.eitanws_exmp.MainActivity.GetArray_Click(MainActivity.java:56) 
10-23 20:02:14.782: E/AndroidRuntime(25237): ... 14 more 

回答

0
Caused by: java.lang.IndexOutOfBoundsException: **Invalid index 4, size is 0** 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at java.util.ArrayList.get(ArrayList.java:304) 
10-23 20:02:14.782: E/AndroidRuntime(25237): at com.example.eitanws_exmp.MainActivity.GetArray_Click(**MainActivity.java:56)** 

好像應用程序是出界試圖使用數組時。 看:索引4無效,大小爲0 你在應用程序中使用任何數組? 試着調試這條線和周圍:MainActivity.java:56 - 它似乎應用程序試圖訪問一個只是空的數組。

修訂

關於NetworkOnMainThreadException

「當應用程序試圖在其主線程進行網絡操作時引發的異常。」

http://developer.android.com/reference/android/os/NetworkOnMainThreadException.html

什麼是您的SDK版本?

+0

感謝您的幫助,數組是空的,因爲程序無法訪問web服務ho填充數組 – Gold

+0

但關於記錄您的應用程序嘗試獲取此數組的索引4。如果數組爲空(大小爲0),那麼在這種情況下您將得到一個異常。 – fycth

相關問題