Pergunta

Hey I've got this problem: In my Android App there's a method that calls a web service using KSOAP. Unfortunately everytime I try to execute this specific method, the whole app crashes. That happens on the virtual as well as the real device.

I've tried to use this tutorial: http://sarangasl.blogspot.de/2011/10/android-web-service-access-tutorial.html

The needed files are imported, KSOAP is added, Eclipse isn't displaying any errors, internet usage is added to Manifest file. The method is called within the XML layout file of a fragment using android:onClick="TestyTest"

I actually have no clue why the app crashes.

private final String NAMESPACE = "http://www.webserviceX.NET/";
    private final String URL = "http://www.webservicex.net/ConvertWeight.asmx";
    private final String SOAP_ACTION = "http://www.webserviceX.NET/ConvertWeight";
    private final String METHOD_NAME = "ConvertWeight";

    public void TestyTest(View view)
    {
        TextView text1 = (TextView) findViewById(R.id.update_text);

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

        String weight = "3700";
        String fromUnit = "Grams";
        String toUnit = "Kilograms";

        PropertyInfo weightProp =new PropertyInfo();
        weightProp.setName("Weight");
        weightProp.setValue(weight);
        weightProp.setType(double.class);
        request.addProperty(weightProp);

        PropertyInfo fromProp =new PropertyInfo();
        fromProp.setName("FromUnit");
        fromProp.setValue(fromUnit);
        fromProp.setType(String.class);
        request.addProperty(fromProp);

        PropertyInfo toProp =new PropertyInfo();
        toProp.setName("ToUnit");
        toProp.setValue(toUnit);
        toProp.setType(String.class);
        request.addProperty(toProp);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            Log.i("myApp", response.toString());


            text1.setText(weight+" "+fromUnit+" equal "+response.toString()+ " "+toUnit);
//            setContentView(tv);

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

    }

In case this helps here the logcat file:

02-20 10:58:06.430: E/dalvikvm(3599): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.test.testy.MainActivity.TestyTest
02-20 10:58:06.430: W/dalvikvm(3599): VFY: unable to resolve new-instance 562 (Lorg/ksoap2/serialization/SoapObject;) in Lcom/test/testy/MainActivity;
02-20 10:58:06.430: D/dalvikvm(3599): VFY: replacing opcode 0x22 at 0x0009
02-20 10:58:06.440: D/dalvikvm(3599): DexOpt: unable to opt direct call 0x0dc6 at 0x0f in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.440: D/dalvikvm(3599): DexOpt: unable to opt direct call 0x0dc2 at 0x1a in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.440: D/dalvikvm(3599): DexOpt: unable to opt direct call 0x0dc2 at 0x2f in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.440: D/dalvikvm(3599): DexOpt: unable to opt direct call 0x0dc2 at 0x44 in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.440: D/dalvikvm(3599): DexOpt: unable to opt direct call 0x0dc9 at 0x5b in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.440: I/dalvikvm(3599): DexOpt: unable to optimize instance field ref 0x0384 at 0x5f in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.440: D/dalvikvm(3599): DexOpt: unable to opt direct call 0x0dcc at 0x68 in Lcom/test/testy/MainActivity;.TestyTest
02-20 10:58:06.560: D/libEGL(3599): loaded /system/lib/egl/libEGL_tegra.so
02-20 10:58:06.600: D/libEGL(3599): loaded /system/lib/egl/libGLESv1_CM_tegra.so
02-20 10:58:06.610: D/libEGL(3599): loaded /system/lib/egl/libGLESv2_tegra.so
02-20 10:58:06.640: D/OpenGLRenderer(3599): Enabling debug mode 0
02-20 10:58:06.860: E/SpannableStringBuilder(3599): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-20 10:58:06.860: E/SpannableStringBuilder(3599): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-20 10:58:06.880: E/SpannableStringBuilder(3599): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-20 10:58:06.880: E/SpannableStringBuilder(3599): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
02-20 10:58:06.910: D/dalvikvm(3599): GC_CONCURRENT freed 154K, 5% free 7631K/7972K, paused 2ms+11ms, total 34ms
02-20 10:58:15.530: D/AndroidRuntime(3599): Shutting down VM
02-20 10:58:15.530: W/dalvikvm(3599): threadid=1: thread exiting with uncaught exception (group=0x41274930)
02-20 10:58:15.540: E/AndroidRuntime(3599): FATAL EXCEPTION: main
02-20 10:58:15.540: E/AndroidRuntime(3599): java.lang.IllegalStateException: Could not execute method of the activity
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.view.View$1.onClick(View.java:3597)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.view.View.performClick(View.java:4202)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.view.View$PerformClick.run(View.java:17340)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.os.Handler.handleCallback(Handler.java:725)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.os.Handler.dispatchMessage(Handler.java:92)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.os.Looper.loop(Looper.java:137)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.app.ActivityThread.main(ActivityThread.java:5039)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at java.lang.reflect.Method.invoke(Method.java:511)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at dalvik.system.NativeStart.main(Native Method)
02-20 10:58:15.540: E/AndroidRuntime(3599): Caused by: java.lang.reflect.InvocationTargetException
02-20 10:58:15.540: E/AndroidRuntime(3599):     at java.lang.reflect.Method.invokeNative(Native Method)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at java.lang.reflect.Method.invoke(Method.java:511)
02-20 10:58:15.540: E/AndroidRuntime(3599):     at android.view.View$1.onClick(View.java:3592)
02-20 10:58:15.540: E/AndroidRuntime(3599):     ... 11 more
02-20 10:58:15.540: E/AndroidRuntime(3599): Caused by: java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
02-20 10:58:15.540: E/AndroidRuntime(3599):     at com.test.testy.MainActivity.TestyTest(MainActivity.java:269)
02-20 10:58:15.540: E/AndroidRuntime(3599):     ... 14 more
Foi útil?

Solução

No clue? The stack trace tells you:

Caused by: java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject

Find the JAR that contains that class and put it in your CLASSPATH.

NoClassDefFoundError has a meaning that's distinct from ClassNotFoundException:

NoClassDefFoundError for code in an Java library on Android

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top