CristianCV
CristianCV

Reputation: 342

Error ksoap2 serialization

I try to make a simple application to pick up a string of a webservice, I have downloaded the package ksopa2, amounts well made and the correct data (tested on Internet tutorials) and I get the error below that you can, you know that might be? thank you very much!

Application:

public class MainActivity extends Activity { 

private static final String SOAP_ACTION = "http://tempuri.org/devuelveString"; //Variables
private static final String METHOD_NAME = "devuelveString";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://localhost:52335/Service1.asmx";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button boton = (Button) findViewById(R.id.Bboton);

    boton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            InvocarWs(); //call the method

        }
    });
}

public void InvocarWs() {
    System.out.println("llama al metodo");
    try {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        final SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11); // utilizar la version que
                                        // corresponda:11 o 12
        envelope.dotNet = true; // para WS ASMX, sólo si fue construido con
                                // .Net
        envelope.setOutputSoapObject(request);

        HttpTransportSE transporte = new HttpTransportSE(URL);

        transporte.call(SOAP_ACTION, envelope);

        SoapPrimitive resultado = (SoapPrimitive) envelope.getResponse();

        System.out.println("" + resultado.toString());

    } catch (Exception e) {
        System.out.println("catch");
    }
}

}

Error logvcat

04-26 08:03:08.731: E/AndroidRuntime(536): FATAL EXCEPTION: main
04-26 08:03:08.731: E/AndroidRuntime(536): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.example.prueba.Conexion.InvocarWs(Conexion.java:24)
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.example.prueba.MainActivity$1.onClick(MainActivity.java:25)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.view.View.performClick(View.java:2485)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.view.View$PerformClick.run(View.java:9080)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.os.Handler.handleCallback(Handler.java:587)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.os.Handler.dispatchMessage(Handler.java:92)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.os.Looper.loop(Looper.java:123)
04-26 08:03:08.731: E/AndroidRuntime(536):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-26 08:03:08.731: E/AndroidRuntime(536):  at java.lang.reflect.Method.invokeNative(Native Method)
04-26 08:03:08.731: E/AndroidRuntime(536):  at java.lang.reflect.Method.invoke(Method.java:507)
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-26 08:03:08.731: E/AndroidRuntime(536):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-26 08:03:08.731: E/AndroidRuntime(536):  at dalvik.system.NativeStart.main(Native Method)

Upvotes: 0

Views: 110

Answers (3)

Manali Sheth
Manali Sheth

Reputation: 379

Try this one:

Steps:

Step-01: Go to Project -> Project Properties -> Java Build Path -> Libraries -> Add External Jars

Step-02: Select your Jar file from its destination

Step-03: In the same window choose the next tab of Libraries which is Order and Export

Step-04: Order and Export -> Mark the checkbox for your library -> OK

Don't create any libs folder, it will automatically do.

I hope this one helps you...:)

Upvotes: 0

No_Rulz
No_Rulz

Reputation: 2719

You need to copy the jar(s) to the libs directory in the project. The ADK picks the libraries from that folder and convert them into classes optimized for Dalvik.

Creating a folder "libs" in the project
Copying the external jars in to the folder
Refresh the folder
Go to properties -> Build path -> Add Jar (not external JAR)
Clean the project
Restart Eclipse

Try this also,

Go to the Order and Export tab on the same popup window
Check the box against the newly added jar

Upvotes: 1

Manoj Fegde
Manoj Fegde

Reputation: 4761

Just copy the ksoap2 jar to your libs folder. Then from your built path add the jar file to your project.

Refresh your project and run. It will run fine.

Upvotes: 0

Related Questions