Android Web服务连接错误

时间:2013-10-22 10:41:55

标签: android web-services

我创建了java soap web服务并尝试将其与android app连接。我创建了一个表im databse作为登录并给出了字段。问题是我的android应用程序代码不是连接并获取数据。它显示没有错误的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 个答案:

答案 0 :(得分: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());
}

答案 1 :(得分:0)

请不要那样做

catch(Exception e){

        }

因为那个

你的logcat是空的

您可以使用

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

代替

答案 2 :(得分: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

答案 3 :(得分:0)

相关问题