我正在尝试从SOAP服务器中提取一些xml以在我的应用程序中使用。我已成功从服务器中拉出一个对象,但无法拉出另一个对象。我拉的第一个对象是用户的ID号。这是我用来提取第一个ID号码的代码:
public class logInTask extends AsyncTask<String, Void, String> {
private static final String SOAP_ACTION = "";
private static final String METHOD_NAME = "checkUserLogin";
private static final String NAMESPACE = "http://m";
private static final String URL = "-sensitive information here, just know that this ends with .cfc?wsdl-";
@Override
public String doInBackground(String... strings) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("usr", strings[0]);
request.addProperty("pwd", strings[1]);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
// SoapPrimitive resultsRequestSOAP = (SoapPrimitive) envelope.getResponse();
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
RESULT = resultsRequestSOAP.toString();
return RESULT;
} catch (Exception e) {
System.out.println("Error" + e);
return "NULL";
}
}
protected void onPostExecute(String result){
if(RESULT.contains("Password Incorrect")) {
alertDialog("Your password is incorrect. Please try again.");
} else if(RESULT.contains("User Not Found")) {
alertDialog("You have entered a non-existing username/email. Please try again.");
} else {
Log.i("BEGINNINGRESULT", RESULT);
RESULT = RESULT.substring(64);
RESULT = RESULT.substring(0, RESULT.indexOf(";"));
alertDialog(RESULT);
startNewIntent(RESULT);
}
}
}
使用此代码,我以字符串的形式从服务器收到响应:
checkUserLoginResponse{checkUserLoginReturn=User Authenticated: 3; }
现在,我转到另一个类进行主菜单esque活动。在这里,我将使用上面的字符串(3)中的整数并将其提供给另一个SOAP请求。这是代码:
public class getUserRegistrations extends AsyncTask<String, Void, String> {
private static final String SOAP_ACTION = "";
private static final String METHOD_NAME = "getUserRegistrations";
private static final String NAMESPACE = "http://m";
private static final String URL = "-same url-";
@Override
public String doInBackground(String... userNumber) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo user = new PropertyInfo();
user.setName("usr");
user.setValue(userNumber);
user.setType(String.class);
request.addProperty(user);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject resultsRequestSOAP = (SoapObject) envelope.getResponse();
androidHttpTransport.responseDump = requestDump;
MainMenuActivity.registrationsGrabbed = resultsRequestSOAP.toString();
return MainMenuActivity.registrationsGrabbed;
} catch (Exception e) {
System.out.println("Error" + e);
return "NULL";
}
}
protected void onPostExecute(String result) {
Log.i("userID", userID);
Log.i("dump", requestDump);
//Log.i("Registration XML:", registrationsGrabbed);
}
}
当我运行应用程序并登录时,我成功传递了userID(第二个类中的userNumber)并尝试将其传递给服务器。但是,我遇到了一个错误。在logcat输出中,我看到:
09-04 15:23:25.313 28519-28519/co.cdat.emi E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: co.cdat.emi, PID: 28519
java.lang.NullPointerException: println needs a message
这会导致应用崩溃。错误来自以下几行:
Log.i("dump", requestDump);
//Log.i("Registration XML:", registrationsGrabbed);
我假设这些错误告诉我服务器没有响应,即使我发送的是同一类型的请求。谁能告诉我我做错了什么?如果您需要更多信息,请询问。谢谢。