开发者

ksoap and minSdkVersion="11" on Android

I have a problem on using ksoap to call a webservice via android. If minSdkVersion="11" then i am getting an exception that you can see below. but if i set the value of minSdkVersion attribute as 9 or under then i am able to call the webservice. What is the matter with ksoap and minsdkversion? Please help me what must i do?

ps: right now i'm going to develop an application which it will be run on tablets (honeycomb). And my target api level has been setted as 11.

Edit: I'm using 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.mai开发者_运维知识库n.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)


You are calling a network operation (the webservice via ksoap) on the main user interface thread. Under api level 11 this is no longer allowed/possible. In any case it is very bad practice to do so since it hangs the UI while the network operation is going on.

Use an AsyncTask and call the webservice in there. Btw. this is totally unrelated to ksoap... any network operation would have this issue.

Also you should upgrade to the latest version of ksoap2-android I release a while ago. 2.4.0 is very old and has a bunch of issues.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜