Saturday, March 29, 2014

android client calls webservice reported abnormal, how it


 package Telephone.test; 

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class TelephoneActivity extends Activity {
/ ** Called when the activity is first created. * /
private EditText phoneSecEditText;
private TextView resultView;
private Button queryButton;
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
queryButton = (Button) findViewById (R.id.query_btn);
queryButton.setOnClickListener (new OnClickListener () {
public void onClick (View v) {

String username = phoneSecEditText.getText () toString () trim ();..
getRemoteInfo (username);
}
});

}
public void getRemoteInfo (String username) {
/ / Namespace
String nameSpace = "http://tempuri.org/";
/ / Method name
callString methodName = "GetUserList";
/ / EndPoint
String endPoint = "http://192.168.0.100:8081/WebService.asmx";
/ / SOAP Action
String soapAction = "http://tempuri.org/GetUserList";

/ / Specify WebService namespace and method name to call
SoapObject rpc = new SoapObject (nameSpace, methodName);

/ / Set the required incoming call WebService interface requires two parameters mobileCode, userId
rpc.addProperty ("username", username);


/ / Generate method call WebService SOAP request message, and specify the version of SOAP
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope (SoapEnvelope.VER11);

envelope.bodyOut = rpc;
/ / Set whether the call is dotNet development WebService
envelope.dotNet = true;
/ / Equivalent to envelope.bodyOut = rpc;
envelope.setOutputSoapObject (rpc);

HttpTransportSE transport = new HttpTransportSE (endPoint);
try {
/ / Call WebService
transport.call (soapAction, envelope);
} Catch (Exception e) {
e.printStackTrace ();
}

/ / Get the returned data
SoapObject object = (SoapObject) envelope.bodyIn;
/ / Get the results returned
String result = object.getProperty (0) toString ();.
/ / String result = "lijian";

/ / Display the results returned by WebService in TextView in
resultView.setText (result);
}
}


<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Nobody answered yet
Reply:
Tip this error:
Reply:
Null pointer exception: phoneSecEditText not only defines the assignment, so in line 27 when this will be reported with a null pointer exception.
 String username = phoneSecEditText.getText (). toString (). trim () ;/ / here phoneSecEditText not assign it 

No comments:

Post a Comment