0

我创建了 java soap web 服务并尝试将它与 android 应用程序连接。我创建了一个表 im 数据库作为登录名并给出了字段。问题是我的 android 应用程序代码不是 connectimg 并获取数据。它没有显示 xml 错误登录页面操作系统加载但按钮中没有任何操作。如果我检查 logcat 没有错误。我已经发布了代码和 logcat 请尽快帮助我。

package com.androidlogin.androidmysql;

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.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;


    public class AndroidLoginActivity extends Activity {
     private final String NAMESPACE = "//hello.android.com";
        private final String URL = "http://192.168.1.210:8090/Myapp/services/Hello?wsdl";
        private final String SOAP_ACTION = "//hello.android.com/sayHello";
        private final String METHOD_NAME = "sayHello";
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            Button login = (Button) findViewById(R.id.btn_login);
            login.setOnClickListener(new View.OnClickListener() {

       public void onClick(View arg0) {
        loginAction();
         //Toast.makeText(AndroidLoginActivity.this, "successfull", Toast.LENGTH_SHORT).show();
       }
      });
        }

       private void loginAction(){
         SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

            EditText userName = (EditText) findViewById(R.id.tf_userName);
            String user_Name = userName.getText().toString();
            EditText userPassword = (EditText) findViewById(R.id.tf_password);
            String user_Password = userPassword.getText().toString();

          //Pass value for userName variable of the web service
            PropertyInfo unameProp =new PropertyInfo();
            unameProp.setName("userName");//Define the variable name in the web service method
            unameProp.setValue(user_Name);//set value for userName variable
            unameProp.setType(String.class);//Define the type of the variable
            request.addProperty(unameProp);//Pass properties to the variable

          //Pass value for Password variable of the web service
            PropertyInfo passwordProp =new PropertyInfo();
            passwordProp.setName("password");
            passwordProp.setValue(user_Password);
            passwordProp.setType(String.class);
            request.addProperty(passwordProp);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            try{
                androidHttpTransport.call(SOAP_ACTION, envelope);
                   SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

                   TextView result = (TextView) findViewById(R.id.tv_status);
                   result.setText(response.toString());

            }
            catch(Exception e){

            }
           }

    }


    **LOGCAT:**


        10-22 15:14:21.614: D/dalvikvm(3946): GC_FOR_MALLOC freed 2697 objects / 408656 bytes in 36ms
        10-22 15:14:28.724: D/dalvikvm(3946): GC_FOR_MALLOC freed 1314 objects / 329208 bytes in 44ms
        10-22 15:14:30.644: D/dalvikvm(3946): GC_FOR_MALLOC freed 662 objects / 305112 bytes in 43ms
        10-22 15:14:31.724: D/dalvikvm(3946): GC_FOR_MALLOC freed 659 objects / 305040 bytes in 43ms
        10-22 15:14:37.695: D/dalvikvm(3946): GC_FOR_MALLOC freed 685 objects / 305872 bytes in 31ms
        10-22 15:14:38.805: D/dalvikvm(3946): GC_FOR_MALLOC freed 661 objects / 305112 bytes in 43ms
        10-22 15:14:39.035: D/dalvikvm(3946): GC_FOR_MALLOC freed 657 objects / 305008 bytes in 30ms
        10-22 15:14:39.245: D/dalvikvm(3946): GC_FOR_MALLOC freed 655 objects / 304920 bytes in 29ms
        10-22 15:14:41.484: W/KeyCharacterMap(3946): No keyboard for id 0
        10-22 15:14:41.484: W/KeyCharacterMap(3946): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
        10-22 15:14:43.064: D/dalvikvm(3946): GC_FOR_MALLOC freed 760 objects / 308400 bytes in 41ms
        10-22 15:14:44.334: D/dalvikvm(3946): GC_FOR_MALLOC freed 661 objects / 305080 bytes in 34ms
        10-22 15:14:46.424: D/dalvikvm(3946): GC_FOR_MALLOC freed 680 objects / 305784 bytes in 35ms
        10-22 15:14:47.624: D/dalvikvm(3946): GC_FOR_MALLOC freed 660 objects / 305104 bytes in 40ms
        10-22 15:14:47.854: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects / 304960 bytes in 31ms
        10-22 15:14:48.064: D/dalvikvm(3946): GC_FOR_MALLOC freed 655 objects / 304928 bytes in 31ms
        10-22 15:14:48.284: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects / 304896 bytes in 30ms
        10-22 15:14:48.504: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects / 304936 bytes in 30ms
        10-22 15:14:48.724: D/dalvikvm(3946): GC_FOR_MALLOC freed 656 objects / 305000 bytes in 30ms
        10-22 15:15:59.594: W/KeyCharacterMap(3946): No keyboard for id 0
        10-22 15:15:59.604: W/KeyCharacterMap(3946): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
        10-22 15:15:59.725: W/IInputConnectionWrapper(3946): showStatusIcon on inactive InputConnection
        10-22 15:16:15.134: D/dalvikvm(3946): GC_EXPLICIT freed 830 objects / 309928 bytes in 117ms
        10-22 15:17:41.604: D/dalvikvm(3946): GC_FOR_MALLOC freed 943 objects / 316984 bytes in 31ms
        10-22 15:21:55.215: W/KeyCharacterMap(3991): No keyboard for id 0
        10-22 15:21:55.215: W/KeyCharacterMap(3991): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
4

4 回答 4

1

显然,您没有看到任何错误,因为您在 catch 子句中没有任何代码。要查看可能的错误的详细描述,请以这种方式修改您的代码(在 DDMS 中添加 logcat 过滤器MyApp ):

try {
        androidHttpTransport.call(SOAP_ACTION, envelope);
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

        TextView result = (TextView) findViewById(R.id.tv_status);
        result.setText(response.toString());

}
catch(Exception e){
        Log.i("MyApp", e.getMessage());
}
于 2013-10-22T10:50:48.177 回答
0

请不要那样做

catch(Exception e){

        }

因此,您的 logcat 为空

你可能会使用

 catch (Exception ex) {
    ex.printStackTrace();
}

反而

于 2013-10-22T10:52:58.170 回答
0

您需要检查您的 logcat。首先包括 -Log.i("MyApp", e.getMessage()); in your catch and then you see the error and post your logcat to see what error you get

于 2013-10-22T11:26:57.587 回答
0
于 2016-05-03T11:24:10.527 回答