我正在使用这样的 AsyncTask
public class AccountReportActivity extends Activity {
private OrgaLevelTask orgaLevelTask;
public void onCreate(Bundle savedInstanceState) {
......
orgaLevelTask = new OrgaLevelTask(AccountReportActivity.this, spinner_orgaLevel, spinner_branch, txt_extra, txt_extra1);
orgaLevelTask.execute();
} //end of onCreate
} //end of class AccountReportActivity
任务:
public class OrgaLevelTask extends AsyncTask<Void, Void, ArrayList<OrgaLevel>> {
//Constrcutor
public OrgaLevelTask(AccountReportActivity accountReportActivity, Spinner spinner_orgaLevel, Spinner spinner_branch, TextView txt_extra, TextView txt_extra1) {
this.accountReportActivity = accountReportActivity;
this.spinner_orgaLevel = spinner_orgaLevel;
....
} //end of constructor
@Override
protected ArrayList<OrgaLevel> doInBackground(Void... arg0) {
return callWebService();
} //end of doInBackground()
private ArrayList<OrgaLevel> callWebService() {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
......
} catch (SocketTimeoutException e) {
Toast.makeText(accountReportActivity, "Service is not connected, Please make sure your server is running", Toast.LENGTH_LONG).show();
return null;
} catch(Exception e) {
e.printStackTrace();
System.out.println();
}
} //end of callWebService()
} //end of class OrgaLevelTask
我的这个任务调用另一个具有相同代码的 AsyncTask。问题是如果服务器正在运行,那么一切都很好。但是,如果服务器没有运行并且我调用了 Web 服务,那么我会得到Force Application close的异常。为什么?我正在处理SocketTimeoutException如果发生异常然后我说在我的 Activity 上显示 toast 但为什么它会强制关闭应用程序。我该如何处理?谢谢