嘿,我有这个问题: 在我的Android App中,有一种使用KSOAP调用Web服务的方法。不幸的是,每次我尝试执行这个特定的方法时,整个应用程序崩溃。这种情况发生在虚拟设备和真实设备上。
我尝试使用本教程:http://sarangasl.blogspot.de/2011/10/android-web-service-access-tutorial.html
导入了所需的文件,添加了KSOAP,Eclipse没有显示任何错误,因此将Internet使用情况添加到Manifest文件中。使用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
答案 0 :(得分:4)
没有头绪?堆栈跟踪告诉您:
Caused by: java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
找到包含该类的JAR并将其放入CLASSPATH。
NoClassDefFoundError
的含义与ClassNotFoundException
不同: