我无法登录。它给我带来了错误。 你能帮忙吗,我用过:How to call a local web service from an Android mobile application
我试过这段代码,但麻烦的是它给了我错误。 要记住的一件事是如果我的登录被传递(或经过身份验证)...我的Web服务返回List not True / False。 我该怎么办 ? 无论如何检查logcat。请。
我真的不知道如何格式化,抱歉有问题。
02-06 16:52:34.285: D/dalvikvm(330): GC_EXTERNAL_ALLOC freed 47K, 53% free 2548K/5379K, external 1625K/2137K, paused 72ms
02-06 16:52:38.246: D/dalvikvm(330): GC_EXTERNAL_ALLOC freed 5K, 53% free 2561K/5379K, external 2727K/3406K, paused 48ms
02-06 16:52:40.196: W/KeyCharacterMap(330): No keyboard for id 0
02-06 16:52:40.206: W/KeyCharacterMap(330): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
02-06 16:52:57.565: I/System.out(330): validateLoginCredentials{username=username; password=password; }
02-06 16:52:57.775: I/dalvikvm(330): Could not find method javax.microedition.io.Connector.open, referenced from method org.ksoap2.transport.ServiceConnectionMidp.<init>
02-06 16:52:57.775: W/dalvikvm(330): VFY: unable to resolve static method 191: Ljavax/microedition/io/Connector;.open (Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
02-06 16:52:57.775: D/dalvikvm(330): VFY: replacing opcode 0x71 at 0x0005
02-06 16:52:57.785: D/dalvikvm(330): VFY: dead code 0x0008-000d in Lorg/ksoap2/transport/ServiceConnectionMidp;.<init> (Ljava/lang/String;)V
02-06 16:52:57.785: I/dalvikvm(330): Could not find method javax.microedition.io.HttpConnection.close, referenced from method org.ksoap2.transport.ServiceConnectionMidp.disconnect
02-06 16:52:57.785: W/dalvikvm(330): VFY: unable to resolve interface method 192: Ljavax/microedition/io/HttpConnection;.close ()V
02-06 16:52:57.785: D/dalvikvm(330): VFY: replacing opcode 0x72 at 0x0002
02-06 16:52:57.785: D/dalvikvm(330): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.disconnect ()V
02-06 16:52:57.797: I/dalvikvm(330): Could not find method javax.microedition.io.HttpConnection.openInputStream, referenced from method org.ksoap2.transport.ServiceConnectionMidp.openInputStream
02-06 16:52:57.797: W/dalvikvm(330): VFY: unable to resolve interface method 193: Ljavax/microedition/io/HttpConnection;.openInputStream ()Ljava/io/InputStream;
02-06 16:52:57.797: D/dalvikvm(330): VFY: replacing opcode 0x72 at 0x0002
02-06 16:52:57.797: D/dalvikvm(330): VFY: dead code 0x0005-0006 in Lorg/ksoap2/transport/ServiceConnectionMidp;.openInputStream ()Ljava/io/InputStream;
02-06 16:52:57.805: I/dalvikvm(330): Could not find method javax.microedition.io.HttpConnection.openOutputStream, referenced from method org.ksoap2.transport.ServiceConnectionMidp.openOutputStream
02-06 16:52:57.805: W/dalvikvm(330): VFY: unable to resolve interface method 194: Ljavax/microedition/io/HttpConnection;.openOutputStream ()Ljava/io/OutputStream;
02-06 16:52:57.805: D/dalvikvm(330): VFY: replacing opcode 0x72 at 0x0002
02-06 16:52:57.805: D/dalvikvm(330): VFY: dead code 0x0005-0006 in Lorg/ksoap2/transport/ServiceConnectionMidp;.openOutputStream ()Ljava/io/OutputStream;
02-06 16:52:57.805: I/dalvikvm(330): Could not find method javax.microedition.io.HttpConnection.setRequestMethod, referenced from method org.ksoap2.transport.ServiceConnectionMidp.setRequestMethod
02-06 16:52:57.805: W/dalvikvm(330): VFY: unable to resolve interface method 195: Ljavax/microedition/io/HttpConnection;.setRequestMethod (Ljava/lang/String;)V
02-06 16:52:57.805: D/dalvikvm(330): VFY: replacing opcode 0x72 at 0x0002
02-06 16:52:57.805: D/dalvikvm(330): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.setRequestMethod (Ljava/lang/String;)V
02-06 16:52:57.815: I/dalvikvm(330): Could not find method javax.microedition.io.HttpConnection.setRequestProperty, referenced from method org.ksoap2.transport.ServiceConnectionMidp.setRequestProperty
02-06 16:52:57.815: W/dalvikvm(330): VFY: unable to resolve interface method 196: Ljavax/microedition/io/HttpConnection;.setRequestProperty (Ljava/lang/String;Ljava/lang/String;)V
02-06 16:52:57.815: D/dalvikvm(330): VFY: replacing opcode 0x72 at 0x0002
02-06 16:52:57.815: D/dalvikvm(330): VFY: dead code 0x0005-0005 in Lorg/ksoap2/transport/ServiceConnectionMidp;.setRequestProperty (Ljava/lang/String;Ljava/lang/String;)V
02-06 16:52:57.825: W/dalvikvm(330): threadid=9: thread exiting with uncaught exception (group=0x40015560)
02-06 16:52:57.855: E/AndroidRuntime(330): FATAL EXCEPTION: AsyncTask #1
02-06 16:52:57.855: E/AndroidRuntime(330): java.lang.RuntimeException: An error occured while executing doInBackground()
02-06 16:52:57.855: E/AndroidRuntime(330): at android.os.AsyncTask$3.done(AsyncTask.java:200)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.lang.Thread.run(Thread.java:1019)
02-06 16:52:57.855: E/AndroidRuntime(330): Caused by: java.lang.NoClassDefFoundError: javax.microedition.io.Connector
02-06 16:52:57.855: E/AndroidRuntime(330): at org.ksoap2.transport.ServiceConnectionMidp.<init>(Unknown Source)
02-06 16:52:57.855: E/AndroidRuntime(330): at org.ksoap2.transport.HttpTransport.getServiceConnection(Unknown Source)
02-06 16:52:57.855: E/AndroidRuntime(330): at org.ksoap2.transport.HttpTransport.call(Unknown Source)
02-06 16:52:57.855: E/AndroidRuntime(330): at com.khosla.nisc.Main.doLogin(Main.java:94)
02-06 16:52:57.855: E/AndroidRuntime(330): at com.khosla.nisc.Main$LoginTask.doInBackground(Main.java:137)
02-06 16:52:57.855: E/AndroidRuntime(330): at com.khosla.nisc.Main$LoginTask.doInBackground(Main.java:1)
02-06 16:52:57.855: E/AndroidRuntime(330): at android.os.AsyncTask$2.call(AsyncTask.java:185)
02-06 16:52:57.855: E/AndroidRuntime(330): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
02-06 16:52:57.855: E/AndroidRuntime(330): ... 4 more
02-06 16:52:59.746: E/WindowManager(330): Activity com.khosla.nisc.Main has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052c7d8 that was originally added here
02-06 16:52:59.746: E/WindowManager(330): android.view.WindowLeaked: Activity com.khosla.nisc.Main has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@4052c7d8 that was originally added here
02-06 16:52:59.746: E/WindowManager(330): at android.view.ViewRoot.<init>(ViewRoot.java:258)
02-06 16:52:59.746: E/WindowManager(330): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
02-06 16:52:59.746: E/WindowManager(330): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
02-06 16:52:59.746: E/WindowManager(330): at android.view.Window$LocalWindowManager.addView(Window.java:424)
02-06 16:52:59.746: E/WindowManager(330): at android.app.Dialog.show(Dialog.java:241)
02-06 16:52:59.746: E/WindowManager(330): at com.khosla.nisc.Main$LoginTask.onPreExecute(Main.java:130)
02-06 16:52:59.746: E/WindowManager(330): at android.os.AsyncTask.execute(AsyncTask.java:391)
02-06 16:52:59.746: E/WindowManager(330): at com.khosla.nisc.Main$1.onClick(Main.java:69)
02-06 16:52:59.746: E/WindowManager(330): at android.view.View.performClick(View.java:2485)
02-06 16:52:59.746: E/WindowManager(330): at android.view.View$PerformClick.run(View.java:9080)
02-06 16:52:59.746: E/WindowManager(330): at android.os.Handler.handleCallback(Handler.java:587)
02-06 16:52:59.746: E/WindowManager(330): at android.os.Handler.dispatchMessage(Handler.java:92)
02-06 16:52:59.746: E/WindowManager(330): at android.os.Looper.loop(Looper.java:123)
02-06 16:52:59.746: E/WindowManager(330): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-06 16:52:59.746: E/WindowManager(330): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 16:52:59.746: E/WindowManager(330): at java.lang.reflect.Method.invoke(Method.java:507)
02-06 16:52:59.746: E/WindowManager(330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-06 16:52:59.746: E/WindowManager(330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-06 16:52:59.746: E/WindowManager(330): at dalvik.system.NativeStart.main(Native Method)
02-06 16:53:01.246: I/Process(330): Sending signal. PID: 330 SIG: 9
答案 0 :(得分:2)
我希望您已将ksoap2
jar文件添加为项目的外部或内部jar,并添加了uses-permission
以访问Manifest
中的INTERNET。
您必须在服务器端的Soap-Service中使用以下代码中的确切参数名称。
request.addProperty("userNAme", user_id);
request.addProperty("passWOrd", password);
此处 UserNAme &amp; passWord 是 SOAP(REQUEST)XML FILE 中的参数。 但 user_id &amp; 密码是存储用户信息的字符串变量。
如何处理您的回复:: -
try
{
httptransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
resultstring = response.toString();
/** do what ever you want with your response, it is stored in "resultString" as a String, you can change it your own form as per usage. **/
}
供您参考。我使用了以下的东西来使用Soap,希望它可以帮到你。
public void SoapService()
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
username = userid.getText().toString();
password = passid.getText().toString();
PropertyInfo UserInfo = new PropertyInfo();
UserInfo.setName("xUserName");
UserInfo.setValue(username);
UserInfo.setType(string.class);
request.addProperty(UserInfo);
PropertyInfo PwdInfo = new PropertyInfo();
PwdInfo.setName("xPassword");
PwdInfo.setValue(password);
PwdInfo.setType(string.class);
request.addProperty(PwdInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE transportSE = new HttpTransportSE(URL);
try
{
transportSE.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.i("myLogin", response.toString());
CheckResponse = response.toString();
if(CheckResponse.equals(fake))
{
intent = new Intent(LoginActivity.this, RunApp.class);
startActivity(intent);
}else
{
Toast.makeText(LoginActivity.this, "Please check your Username and Password" , Toast.LENGTH_SHORT).show();
}
}catch(Exception e)
{
e.printStackTrace();
}
Toast.makeText(LoginActivity.this, CheckResponse, Toast.LENGTH_SHORT).show();
}// end of SoapService
在我的情况下, xUserName和xPassword 是SoapRequest参数。 假是一个字符串,文字登录成功。
希望这对你有所帮助。
尝试在项目中添加日志并获取确切的问题位置。
玩得开心,快乐的编程......