我在如何使用 ksoap2 我的代码连接到 Web 服务时遇到问题:
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();
}
}
}
它说 Application MyTest (process com.falafel.mytest)) 已意外停止!!:(
我的错误:
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
任何帮助将不胜感激,谢谢!