我有来自logcat的错误:
03-19 16:57:28.715: E/dalvikvm(11924): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.project.newproject.MainActivity$1.onClick
03-19 16:57:28.715: W/dalvikvm(11924): VFY: unable to resolve new-instance 554 (Lorg/ksoap2/serialization/SoapObject;) in Lcom/project/newproject/MainActivity$1;
03-19 16:57:28.715: D/dalvikvm(11924): VFY: replacing opcode 0x22 at 0x0000
03-19 16:57:28.715: D/dalvikvm(11924): DexOpt: unable to opt direct call 0x0de9 at 0x06 in Lcom/project/newproject/MainActivity$1;.onClick
03-19 16:57:28.715: D/dalvikvm(11924): DexOpt: unable to opt direct call 0x0deb at 0x0d in Lcom/project/newproject/MainActivity$1;.onClick
03-19 16:57:28.715: I/dalvikvm(11924): DexOpt: unable to optimize instance field ref 0x034d at 0x11 in Lcom/project/newproject/MainActivity$1;.onClick
03-19 16:57:28.715: D/dalvikvm(11924): DexOpt: unable to opt direct call 0x0dee at 0x1a in Lcom/project/newproject/MainActivity$1;.onClick
03-19 16:57:28.790: D/CLIPBOARD(11924): Hide Clipboard dialog at Starting input: finished by someone else... !
03-19 16:57:31.220: D/AndroidRuntime(11924): Shutting down VM
03-19 16:57:31.220: W/dalvikvm(11924): threadid=1: thread exiting with uncaught exception (group=0x40c2f1f8)
03-19 16:57:31.220: E/AndroidRuntime(11924): FATAL EXCEPTION: main
03-19 16:57:31.220: E/AndroidRuntime(11924): java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
03-19 16:57:31.220: E/AndroidRuntime(11924): at com.project.newproject.MainActivity$1.onClick(MainActivity.java:34)
03-19 16:57:31.220: E/AndroidRuntime(11924): at android.view.View.performClick(View.java:3591)
03-19 16:57:31.220: E/AndroidRuntime(11924): at android.view.View$PerformClick.run(View.java:14263)
03-19 16:57:31.220: E/AndroidRuntime(11924): at android.os.Handler.handleCallback(Handler.java:605)
03-19 16:57:31.220: E/AndroidRuntime(11924): at android.os.Handler.dispatchMessage(Handler.java:92)
03-19 16:57:31.220: E/AndroidRuntime(11924): at android.os.Looper.loop(Looper.java:137)
03-19 16:57:31.220: E/AndroidRuntime(11924): at android.app.ActivityThread.main(ActivityThread.java:4507)
03-19 16:57:31.220: E/AndroidRuntime(11924): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 16:57:31.220: E/AndroidRuntime(11924): at java.lang.reflect.Method.invoke(Method.java:511)
03-19 16:57:31.220: E/AndroidRuntime(11924): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
03-19 16:57:31.220: E/AndroidRuntime(11924): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
03-19 16:57:31.220: E/AndroidRuntime(11924): at dalvik.system.NativeStart.main(Native Method)
03-19 16:58:54.010: I/Process(11924): Sending signal. PID: 11924 SIG: 9
虽然我无法正确运行,但我已经尝试了所有我知道的内容。最后,我完全复制了代码来测试我的Web服务; http://mustafa-yildirim.blogspot.com/2010/09/android-net-web-servis-baglants.html以下是我的代码。
package com.project.newproject;
import java.io.IOException;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.ksoap2.*;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.xmlpull.v1.XmlPullParserException;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
private static final String SOAP_ACTION = "http://tempuri.org/HelloWorld";
private static final String METHOD_NAME = "HelloWorld";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String URL = "http://mysite/service1.asmx";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button btn_goster = (Button) findViewById(R.id.btn_goster);
final EditText edt_goster = (EditText) findViewById(R.id.edt_goster);
btn_goster.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
AndroidHttpTransport httpTransport = new AndroidHttpTransport(URL);
SoapPrimitive result = null;
try {
httpTransport.call(SOAP_ACTION, envelope);
result = (SoapPrimitive) envelope.getResponse();
edt_goster.setText(result.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
edt_goster.setText(e.getMessage());
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
edt_goster.setText(e.getMessage());
}
}
});
}
一切都一样且没有错误,但是当我运行AVD或手机时,会显示一条名为“新项目已停止”的消息。我每次都得到它:(
答案 0 :(得分:0)