我在使用ksoap通过android调用web服务时遇到问题。如果minSdkVersion =“11”,那么我得到一个例外,你可以在下面看到。但如果我将minSdkVersion属性的值设置为9或更低,那么我可以调用webservice 。 ksoap和minsdkversion有什么关系?请帮帮我,我该怎么办?
ps:现在我将开发一个应用程序,它将在平板电脑(蜂窝)上运行。我的目标api级别已设置为11.
编辑:我正在使用ksoap2-android-assembly-2.4-jar-with-dependencies
07-19 11:16:03.604: ERROR/AndroidRuntime(782): FATAL EXCEPTION: main
07-19 11:16:03.604: ERROR/AndroidRuntime(782): android.os.NetworkOnMainThreadException
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:368)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at java.net.Socket.connect(Socket.java:901)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:217)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:46)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:68)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at com.quadro.main.Soap.AndSoap.CallService(AndSoap.java:40)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at com.quadro.main.Login.onClick(Login.java:27)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.view.View.performClick(View.java:3100)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.view.View$PerformClick.run(View.java:11644)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.os.Handler.handleCallback(Handler.java:587)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.os.Handler.dispatchMessage(Handler.java:92)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.os.Looper.loop(Looper.java:126)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at android.app.ActivityThread.main(ActivityThread.java:3997)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at java.lang.reflect.Method.invokeNative(Native Method)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at java.lang.reflect.Method.invoke(Method.java:491)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
07-19 11:16:03.604: ERROR/AndroidRuntime(782): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
您正在主用户界面线程上调用网络操作(通过ksoap进行Web服务)。在api级别11下,不再允许/可能。在任何情况下,这都是非常糟糕的做法,因为它在网络操作进行时挂起了UI。
使用AsyncTask并在那里调用webservice。顺便说一句。这与ksoap完全无关......任何网络操作都会遇到这个问题。
另外你应该升级到我最近发布的最新版本的ksoap2-android。 2.4.0很老了,有很多问题。