1

我正在学习如何通过 KSOAP 在移动平台(特别是 Android)上使用 Web 服务。但是,我在创建SoapObject.

String NAMESPACE = "http://webservicesx.net/";
String METHOD_NAME = "ChangeMetricWeightUnit";
String SOAP_ACTION = NAMESPACE + METHOD_NAME;
String URL = "http://173.201.44.188/convertMetricWeight.asmx";

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

我的代码在应用程序启动和调试时崩溃表明SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);抛出了InvocationTargetException.

我的 LogCat 如下:

06-06 19:53:18.900: E/AndroidRuntime(995): FATAL EXCEPTION: main
06-06 19:53:18.900: E/AndroidRuntime(995): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
06-06 19:53:18.900: E/AndroidRuntime(995):  at org.hcfcd.webtest.WebServicesTest.onCreate(WebServicesTest.java:31)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.os.Handler.dispatchMessage(Handler.java:99)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.os.Looper.loop(Looper.java:130)
06-06 19:53:18.900: E/AndroidRuntime(995):  at android.app.ActivityThread.main(ActivityThread.java:3683)
06-06 19:53:18.900: E/AndroidRuntime(995):  at java.lang.reflect.Method.invokeNative(Native Method)
06-06 19:53:18.900: E/AndroidRuntime(995):  at java.lang.reflect.Method.invoke(Method.java:507)
06-06 19:53:18.900: E/AndroidRuntime(995):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-06 19:53:18.900: E/AndroidRuntime(995):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-06 19:53:18.900: E/AndroidRuntime(995):  at dalvik.system.NativeStart.main(Native Method)

从我从 LogCat 中可以看出,尽管我将 KSOAP.jar 导入到项目中,但编译器找不到 SoapObject 类。

4

2 回答 2

0

使用 ksoap2 库处理 android 问题时可能会出现相同的异常问题。试试这个

于 2012-06-07T06:32:47.077 回答
-1

我不完全确定为什么这会起作用,而是像这样围绕SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);在一个try块中:

try {
SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
...
}

导致我的代码正确编译和执行。不太清楚为什么简单地将它包围在一个try块中使它起作用,所以对该注释的任何澄清都会很好。

于 2012-06-07T12:28:32.690 回答