如何修复无响应的按钮及其onClick()方法?

时间:2013-04-08 06:15:17

标签: android web-services soap login

单击登录按钮不会产生Web服务的响应,并且没有异常或其他可见错误。我该如何修理我的按钮?

代码:

public class Oral extends Activity {

String NAMESPACE = "http://mlxserver/";
    String METHOD_NAME = "loginAuthentication";
String SOAP_ACTION = "http://mlxserver/MX_AgentService/loginAuthentication";
String URL = "http://mlxserver//HTTKSvc/MX_AgentService.svc?wsdl";

EditText et1,et2,et3;
Button bt1;
   @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_oral);
     et1 = (EditText) findViewById(R.id.editText1);
     et2 = (EditText) findViewById(R.id.editText2);
     et3 = (EditText) findViewById(R.id.editText3);
     bt1 = (Button) findViewById(R.id.button1);
     bt1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
                                 request.addProperty("USERNAME",et1.getText().toString());  
                request.addProperty("PASSWORD",et2.getText().toString());
                request.addProperty("PIN",et3.getText().toString());

              /*  String authentication = android.util.Base64.encodeToString("username:password".getBytes(), android.util.Base64.DEFAULT);
                List<HeaderProperty> headers = new ArrayList<HeaderProperty>();
                headers.add(new HeaderProperty("Authorization","Basic " +authentication));
               */

                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(request);

                try {
                  HttpTransportSE httpTransport = new HttpTransportSE(URL);  
                  httpTransport.call(SOAP_ACTION, envelope);    
                  SoapObject result = (SoapObject)envelope.getResponse(); 

                if(result != null)
                {

                      et1.setText(result.getProperty(0).toString());
                      et2.setText(result.getProperty(0).toString());
                      et3.setText(result.getProperty(0).toString());

                      Intent next = new Intent (getApplicationContext(),Second.class);
                      startActivity(next);
                }
                else
                {
                      Toast.makeText(getApplicationContext(), "Enter USERNAME",Toast.LENGTH_LONG).show();
                      Toast.makeText(getApplicationContext(), "Enter PASSWORD",Toast.LENGTH_LONG).show();
                      Toast.makeText(getApplicationContext(), "Enter PIN",Toast.LENGTH_LONG).show();
                }
          } catch (Exception e) {
                e.printStackTrace();
          } 
          } 


    });


}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.oral, menu);
    return true;
}

}

1 个答案:

答案 0 :(得分:0)

它可能抛出异常。您是否在android清单文件中授予了访问权限?

如果你的互联网权限可能会输入异常,或者输入服务器网址/登录是错误的......等等。

记录异常。