-1
I am implenting java web services for android project and calling with KSOAP2.
My Code is mention below..

package com.android.service;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MyAndroidService extends Activity {
    private static final String NAMESPACE = "http://project.com/";
    private static final String METHOD_NAME = "sayHello";
    String SOAP_ACTION = "http://project.com/sayHello";
    private static final String URL = 
            "http://localhost:8080/MyProject/wsdl/Hello.wsdl";  
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv=(TextView)findViewById(R.id.text);

        try{
            SoapObject object=new SoapObject(NAMESPACE, METHOD_NAME);
            object.addProperty("name", "dev");
            SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(object);
            HttpTransportSE httpTransportSE=new HttpTransportSE(URL);
            httpTransportSE.call(SOAP_ACTION, envelope);
            Object result=envelope.getResponse();
            System.out.println("result :"+result.toString());
        }catch (Exception e) {
            System.out.println(e);
        }
    }
}

but we are always getting an extion which is also mention below

08-28 17:32:18.378: E/AndroidRuntime(6739): FATAL EXCEPTION: main
08-28 17:32:18.378: E/AndroidRuntime(6739): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
08-28 17:32:18.378: E/AndroidRuntime(6739):     at com.android.service.MyAndroidService.onCreate(MyAndroidService.java:24)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.os.Looper.loop(Looper.java:123)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at java.lang.reflect.Method.invokeNative(Native Method)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at java.lang.reflect.Method.invoke(Method.java:521)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
08-28 17:32:18.378: E/AndroidRuntime(6739):     at dalvik.system.NativeStart.main(Native Method)
Alexis C.
  • 91,686
  • 21
  • 171
  • 177

1 Answers1

1

It obviously can't find the ksoap2 jar at runtime.

You may check that your jar is exported when building apk: in project Properties > Java Build Path, go to the 'Order and Export' folder and fill the checkbox corresponding to your jar. And rebuild.

sdabet
  • 18,360
  • 11
  • 89
  • 158
  • i did already but after that it also given the same exception – user1412354 Aug 28 '12 at 12:41
  • 08-28 18:26:06.605: I/System.out(7310): exception :org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions targetNamespace='http://project.com'>@2:316 in java.io.InputStreamReader@481830d8) – user1412354 Aug 28 '12 at 12:58
  • So you don't get the previous NoClassDefFoundError error anymore? – sdabet Aug 28 '12 at 12:59
  • thanks sir but after that we are getting exception just like above can u help me how to resolve it. – user1412354 Aug 29 '12 at 04:26
  • That looks like a totally different problem now (obviously an error of response parsing). You should consider creating a new question for this. – sdabet Aug 29 '12 at 07:04