我的应用程序在运行时崩溃了。但是如果我创建一个Java
类并执行相同的代码(删除Toast
),它就能正常工作。
有什么想法吗?
我在ksoap2-android-full-2.1.2
和Android
项目的课程路径中添加了Java
。
代码:
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("UserID", "admin");
request.addProperty("Password", "admin");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) (envelope.bodyIn);
if (Integer.parseInt(response.getProperty("UserValidationResponse").toString()) == 0) {
userAuthenticated = true;
Toast.makeText(getApplicationContext(), "User Authenticated...", Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
System.out.println();
Toast.makeText(getApplicationContext(), "User Not Authenticated...", Toast.LENGTH_SHORT).show();
}
logcat的:
12-27 18:54:25.003: E/dalvikvm(690): Could not find class 'org.ksoap2.serialization.SoapObject', referenced from method com.micros.retail.LoginActivity.doLogin
12-27 18:54:41.203: E/AndroidRuntime(690): FATAL EXCEPTION: main
12-27 18:54:41.203: E/AndroidRuntime(690): java.lang.IllegalStateException: Could not execute method of the activity
12-27 18:54:41.203: E/AndroidRuntime(690): at android.view.View$1.onClick(View.java:2144)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.view.View.performClick(View.java:2485)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.view.View$PerformClick.run(View.java:9080)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.os.Handler.handleCallback(Handler.java:587)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.os.Handler.dispatchMessage(Handler.java:92)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.os.Looper.loop(Looper.java:123)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.app.ActivityThread.main(ActivityThread.java:3683)
12-27 18:54:41.203: E/AndroidRuntime(690): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 18:54:41.203: E/AndroidRuntime(690): at java.lang.reflect.Method.invoke(Method.java:507)
12-27 18:54:41.203: E/AndroidRuntime(690): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-27 18:54:41.203: E/AndroidRuntime(690): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-27 18:54:41.203: E/AndroidRuntime(690): at dalvik.system.NativeStart.main(Native Method)
12-27 18:54:41.203: E/AndroidRuntime(690): Caused by: java.lang.reflect.InvocationTargetException
12-27 18:54:41.203: E/AndroidRuntime(690): at java.lang.reflect.Method.invokeNative(Native Method)
12-27 18:54:41.203: E/AndroidRuntime(690): at java.lang.reflect.Method.invoke(Method.java:507)
12-27 18:54:41.203: E/AndroidRuntime(690): at android.view.View$1.onClick(View.java:2139)
12-27 18:54:41.203: E/AndroidRuntime(690): ... 11 more
12-27 18:54:41.203: E/AndroidRuntime(690): Caused by: java.lang.NoClassDefFoundError: org.ksoap2.serialization.SoapObject
12-27 18:54:41.203: E/AndroidRuntime(690): at com.micros.retail.LoginActivity.doLogin(LoginActivity.java:56)
12-27 18:54:41.203: E/AndroidRuntime(690): at com.micros.retail.LoginActivity.onClick(LoginActivity.java:48)
12-27 18:54:41.203: E/AndroidRuntime(690): ... 14 more
答案 0 :(得分:1)
在你的android项目的libs文件夹下添加ksoap2-android-full-2.1.2
jar。