简体   繁体   English

在 Android 上的 ksoap 和 minSdkVersion=“11”

[英]ksoap and minSdkVersion=“11” on Android

I have a problem on using ksoap to call a webservice via android.我在使用 ksoap 通过 android 调用 web 服务时遇到问题。 If minSdkVersion="11" then i am getting an exception that you can see below.如果 minSdkVersion="11" 那么我得到一个异常,你可以在下面看到。 but if i set the value of minSdkVersion attribute as 9 or under then i am able to call the webservice .但是如果我将 minSdkVersion 属性的值设置为 9 或以下,那么我就可以调用 webservice What is the matter with ksoap and minsdkversion? ksoap 和 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). ps:现在我要开发一个应用程序,它将在平板电脑(蜂窝)上运行。 And my target api level has been setted as 11.我的目标 api 级别已设置为 11。

Edit: I'm using ksoap2-android-assembly-2.4-jar-with-dependencies编辑:我正在使用 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)

You are calling a network operation (the webservice via ksoap) on the main user interface thread.您正在主用户界面线程上调用网络操作(通过 ksoap 的 Web 服务)。 Under api level 11 this is no longer allowed/possible.在 api 级别 11 下不再允许/可能。 In any case it is very bad practice to do so since it hangs the UI while the network operation is going on.无论如何,这样做是非常糟糕的做法,因为它会在网络操作正在进行时挂起 UI。

Use an AsyncTask and call the webservice in there.使用 AsyncTask 并在那里调用 web 服务。 Btw.顺便提一句。 this is totally unrelated to ksoap... any network operation would have this issue.这与 ksoap 完全无关……任何网络操作都会有这个问题。

Also you should upgrade to the latest version of ksoap2-android I release a while ago.此外,您应该升级到我不久前发布的最新版本的 ksoap2-android。 2.4.0 is very old and has a bunch of issues. 2.4.0 已经很老了,有很多问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM