1

I am learning how to use Web services on a mobile platform (specifically Android) with KSOAP. However, I seem to be running into a problem when creating a 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);

My code crashes on application start and debugging has shown that the SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); throws an InvocationTargetException.

My LogCat is as follows:

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)

From what I can tell from the LogCat, the compiler couldn't find the SoapObject class despite the fact that I imported the KSOAP.jar into the project.

Jason L
  • 1,812
  • 2
  • 22
  • 43

2 Answers2

0

May be the same problem with exception while using ksoap2 library for android question. Try this.

Community
  • 1
  • 1
Oguz Ozkeroglu
  • 3,025
  • 3
  • 38
  • 64
  • For some reason, simply surrounding the creation of the SOAP object with a try block seemed to work. – Jason L Jun 08 '12 at 13:49
-1

I'm not exactly sure why this worked but surrounding SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); in a try block like so:

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

resulted in my code compiling and executing properly. Not quite sure why simply surrounding it in a try block made it work so any clarification on that note would be nice.

Jason L
  • 1,812
  • 2
  • 22
  • 43