我给你简要描述一下你的问题。
有很多可能您没有从服务器获取数据
如果您的网络速度很慢,并且您尝试从服务器和 XML 数据中获取所有信息,那么在这种情况下,如果网络崩溃,则会显示错误
如果您向不在服务器中的页面发出请求
现在,如果您在代码中遇到问题,那么我会为您提供我在项目中实现的 AsyncTask 类的完整代码,它工作正常。
private class GetLoginResponse extends AsyncTask<Void, Void, Boolean> {
private ProgressDialog progressDialog;
private String email;
private String password;
public GetLoginResponse(String emailId, String paswd) {
this.email = emailId;
this.password = paswd;
}
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(LoginActivity.this, "",
"Loading....", true, false);
}
@Override
protected Boolean doInBackground(Void... params) {
try {
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response = httpclient.execute(httpGet);
//here u can check the reponse is ok and 200
} catch (NetworkException e) {
isNetworkError = true;
}
return false;
}
@Override
protected void onPostExecute(Boolean data) {
progressDialog.dismiss();
System.out.println("lOGIN RESPONSE for email = " + email + data);
}
}// end AsyncTask
这将解决您的问题。