在我的应用程序中,我在该登录页面中创建了登录页面,我输入了用户名和密码详细信息,并发送了请求参数,当我尝试单击登录按钮时,Web 服务调用并从给定的响应中获取用户名和密码SOAP URL,但是当我尝试获取响应时,xml pull 解析器异常会发生在我在这里犯错的地方,我附上了我的代码,任何人都可以帮助我解决这个异常。
登录活动
public class LoginActivity extends Activity {
//Set Error Status
static boolean errored = false;
Button Login;
TextView Showtext;
EditText userName , passWord;
ProgressBar webservicePG;
String editTextUsername;
boolean loginStatus;
String editTextPassword;
public static String nameValue;
public static String passwordvalue;
int MC_loginRequest = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
SharedPreferences prefs = this.getSharedPreferences("com.hubino.sozo", Context.MODE_PRIVATE);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
userName = (EditText) findViewById(R.id.usernametext);
passWord = (EditText) findViewById(R.id.passwordtext);
Showtext = (TextView) findViewById(R.id.showtext);
Login = (Button) findViewById(R.id.login);
webservicePG = (ProgressBar) findViewById(R.id.progressBar1);
Login.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
userName.setHintTextColor(getResources().getColor(R.color.red));
userName.setHint(Html.fromHtml("<small><small>" +
getString(R.string.hint) + "</small></small>"));
passWord.setHintTextColor(getResources().getColor(R.color.red));
passWord.setHint(Html.fromHtml("<small><small>" +
getString(R.string.password) + "</small></small>"));
if (userName.getText().length() != 0 && userName.getText().toString() != "") {
if(passWord.getText().length() != 0 && passWord.getText().toString() != ""){
editTextUsername = userName.getText().toString();
editTextPassword = passWord.getText().toString();
Showtext.setText("");
nameValue = userName.getText().toString();
passwordvalue = passWord.getText().toString();
haredPreferences.Editor prefs = LoginActivity.this.getSharedPreferences(
"com.hubino.sozo", Context.MODE_PRIVATE).edit();
prefs.putString("name",nameValue);
prefs.putString("number",passwordvalue);
prefs.commit();
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
}
}
});
}
private class AsyncCallWS extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
loginStatus = WebService.Loginvalue(editTextUsername,editTextPassword,"mc_login");
loginStatus = true;
return null;
}
@Override
protected void onPostExecute(String result) {
webservicePG.setVisibility(View.INVISIBLE);
Intent intObj = new Intent(LoginActivity.this,MenuActivity.class);
if(!errored){
if(loginStatus){
startActivity(intObj);
}else{
Showtext.setText("Login Failed, try again");
}
}else{
Showtext.setText("Error occured in invoking webservice");
}
errored = false;
}
@Override
protected void onPreExecute() {
webservicePG.setVisibility(View.VISIBLE);
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
public static Object password() {
// TODO Auto-generated method stub
return null;
}
}
**WebService**
public class WebService extends AsyncTask<String, Void, String> {
private static mc_loginRequest MC_loginRequest = null;
private static final String NAMESPACE = " ";
private static final String URL = " ";
private static final String SOAP_ACTION = " ";
private static final String METHOD = "mc_login";
@SuppressWarnings("null")
public static boolean Loginvalue(String usrname,String passwd, String mc_login) {
MC_loginRequest = new mc_loginRequest();
boolean loginStatus = false;
SoapObject request = new SoapObject(NAMESPACE, METHOD);
PropertyInfo pi = new PropertyInfo();
MC_loginRequest.username=usrname;
MC_loginRequest.password=passwd;
pi.setName("MC_loginRequest");
pi.setValue(MC_loginRequest);
pi.setType(MC_loginRequest.getClass());
request.addProperty(pi);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "MC_loginRequest", mc_loginRequest.class);
envelope.bodyOut = request;
HttpTransportSE transport = new HttpTransportSE(URL);
transport.debug = true;
envelope.dotNet = true;
envelope.encodingStyle = SoapEnvelope.ENC;
try {
transport.call(SOAP_ACTION+METHOD, envelope);
SoapPrimitive loginresponse = (SoapPrimitive) envelope.getResponse();
loginStatus = Boolean.parseBoolean(loginresponse.toString());
}
catch (Exception e)
{
LoginActivity.errored = false;
e.printStackTrace();
Log.e("YOUR_APP_LOG_TAG", "I got an error", e);
}
return loginStatus;
}
protected SoapObject doInBackground(Integer... branchNumber) {
return null;
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
return null;
}
}
**mc_loginRequest**
public class mc_loginRequest implements KvmSerializable {
public String username;
public String password;
@Override
public Object getProperty(int arg0) {
switch (arg0){
case 0:
return username;
case 1:
return password;
default:
return null;
}
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return 1;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.type = PropertyInfo.STRING_CLASS;
info.name = "username";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "password";
break;
default:
break;
}
}
@Override
public void setProperty(int index, Object value) {
switch(index)
{
case 0:
username = value.toString();
break;
case 1:
password = value.toString();
break;
default:
break;
}
}
}
`