-1

I got problem on how I connected to web service using ksoap2 my code :

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.*;
import org.ksoap2.transport.HttpTransportSE;
import android.widget.TextView;


public class FirstScreen extends Activity {

private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
private static final String METHOD_NAME = "CelsiusToFahrenheit";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";
TextView tv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_first_screen);
    tv= (TextView)findViewById(R.id.TextView01);

    SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
    Request.addProperty("Celsius", "32");

    SoapSerializationEnvelope soapEnvelope =  new SoapSerializationEnvelope(SoapEnvelope.VER10);
    soapEnvelope.dotNet =true;
    soapEnvelope.setOutputSoapObject(Request);

    HttpTransportSE bah = new HttpTransportSE(URL);

    try
    {
        bah.call(SOAP_ACTION, soapEnvelope);
        SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
        tv.setText("status: "  + resultString);

    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

}

}

it says Application MyTest (process com.falafel.mytest)) has stopped unexpectedly!! :(

my error:

10-10 13:14:06.690: E/dalvikvm(279): Could not find class  'org.ksoap2.serialization.SoapObject', referenced from method com.falafel.mytest.FirstScreen.onCreate
10-10 13:14:06.690: W/dalvikvm(279): VFY: unable to resolve new-instance 501 (Lorg/ksoap2/serialization/SoapObject;) in Lcom/falafel/mytest/FirstScreen;
10-10 13:14:06.690: D/dalvikvm(279): VFY: replacing opcode 0x22 at 0x0012
10-10 13:14:06.690: D/dalvikvm(279): VFY: dead code 0x0014-005a in Lcom/falafel/mytest/FirstScreen;.onCreate (Landroid/os/Bundle;)V
10-10 13:14:06.870: W/Resources(279): Converting to string: TypedValue{t=0x12/d=0x0 a=2 r=0x7f070000}
10-10 13:14:06.890: D/AndroidRuntime(279): Shutting down VM
10-10 13:14:06.890: W/dalvikvm(279): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
10-10 13:14:06.920: E/AndroidRuntime(279): FATAL EXCEPTION: main
10-10 13:14:06.920: E/AndroidRuntime(279): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
10-10 13:14:06.920: E/AndroidRuntime(279):  at com.falafel.mytest.FirstScreen.onCreate(FirstScreen.java:32)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.os.Looper.loop(Looper.java:123)
10-10 13:14:06.920: E/AndroidRuntime(279):  at android.app.ActivityThread.main(ActivityThread.java:4627)
10-10 13:14:06.920: E/AndroidRuntime(279):  at java.lang.reflect.Method.invokeNative(Native Method)
10-10 13:14:06.920: E/AndroidRuntime(279):  at java.lang.reflect.Method.invoke(Method.java:521)
10-10 13:14:06.920: E/AndroidRuntime(279):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-10 13:14:06.920: E/AndroidRuntime(279):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-10 13:14:06.920: E/AndroidRuntime(279):  at dalvik.system.NativeStart.main(Native Method)
 10-10 13:14:11.240: I/Process(279): Sending signal. PID: 279 SIG: 9

Any Help would be appriciated, thank you!

Shaf
  • 3
  • 1
  • 5
  • you didn't even try ... "java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject" + google ... first result ... – Selvin Oct 10 '12 at 13:29

2 Answers2

0

Have you done it

Project > Properties > Java Build Path > Order and Export > and finally, checkmark your imported KSOAP2 library.

Also, don't consume a webservice on UI thread, consider a service or AsyncTask

ThePCWizard
  • 3,338
  • 2
  • 21
  • 32
0

Using ksoap2 in Android can be challenging sometimes. As ThePCWizard rightly suggested it is better to carry out all network related tasks on the background thread using an AsyncTask.

You getting a java.lang.NoClassDefFoundError might suggest that the ksoap.jar isn't recognized by your Android project.

Assuming you have the latest ADT version installed, you need to add the .jar file in the libs folder of your Android project. After that right click the .jar file -->Build path-->Add to build path.

Clean your project and try running the application. It should remove the class definition not found error.

I had implemented a similar application quite some time back. Here is the link.

Hope it helps!

Community
  • 1
  • 1
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129