我正在学习如何通过 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 类。