3
我有一個函數,連接到一個Web服務並返回SoapObject。如果我在沒有AsyncTask的情況下直接調用它,但是下面的代碼拋出一個異常,這個函數沒有問題。有什麼建議麼?Android ksoap2拋出異常與AsyncTask
private class LoginTask extends AsyncTask<String, Object, Object> {
protected SoapObject doInBackground(String... params) {
try
{
return callWebService("a","a");
}
catch (Exception e)
{
return null;
}
}
protected void onPostExecute(SoapObject result) {
setErrorText(result);
}
}
private SoapObject callWebService(String UserName, String Password) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("UserName", UserName);
request.addProperty("Password", Password);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject) envelope.getResponse(); //this code causes the problem
return response;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (XmlPullParserException e) {
e.printStackTrace();
return null; //Directly jumps to here
}
}
你有什麼異常? – Venkat
我加了callWebService函數。代碼直接跳轉到返回null ;. – user1805390
你被問到異常而不是方法 –