gpt4 book ai didi

Android ksoap2 使用 AsyncTask 抛出异常

转载 作者:太空狗 更新时间:2023-10-29 15:15:15 24 4
gpt4 key购买 nike

我有一个连接到 Web 服务并返回 SoapObject 的函数。如果我在没有 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
}

}

最佳答案

如果您更改任务声明:

    private class LoginTask extends AsyncTask<String, Object, Object>

    private class LoginTask extends AsyncTask<String, Object, SoapObject>

您的 onPostExecute() 应该执行。

关于Android ksoap2 使用 AsyncTask 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13265331/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com