1

この問題があります。私の Android アプリには、KSOAP を使用して Web サービスを呼び出すメソッドがあります。残念ながら、この特定のメソッドを実行しようとするたびに、アプリ全体がクラッシュします。これは、仮想デバイスだけでなく、実際のデバイスでも発生します。

このチュートリアルを使用しようとしました: http://sarangasl.blogspot.de/2011/10/android-web-service-access-tutorial.html

必要なファイルがインポートされ、KSOAP が追加され、Eclipse でエラーが表示されなくなり、インターネットの使用状況がマニフェスト ファイルに追加されます。このメソッドは、android:onClick="TestyTest" を使用してフラグメントの XML レイアウト ファイル内で呼び出されます。

アプリがクラッシュする理由は実際にはわかりません。

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();
        }

    }

これがlogcatファイルに役立つ場合:

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
4

1 に答える 1

4

全く分からない?スタック トレースは次のことを示します。

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

そのクラスを含む JAR を見つけて、CLASSPATH に入れます。

NoClassDefFoundErrorとは異なる意味を持ちますClassNotFoundException:

Android の Java ライブラリ内のコードの NoClassDefFoundError

于 2013-02-20T10:03:52.943 に答える