У меня проблема с этим занятием.
package com.ilocal.diary;
import java.util.ArrayList;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
public class ViewDiary extends Activity {
private String userid = "1";
private String response;
private String url;
private Bundle bundle = new Bundle();
private ArrayList<NameValuePair> postParameters;
private ProgressDialog dialog = null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.empty_layout);
this.dialog = ProgressDialog.show(this, "Working..", "Downloading Data...", true, false);
bundle = this.getIntent().getExtras();
if (bundle != null) {
userid = bundle.getString("USERID");
}
url ="http://www.ilocaltest.x10.mx/android/fetchdiary.php";
postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("userid", userid));
new PHPQuery().execute(url, postParameters);
}
private class PHPQuery extends AsyncTask<Object, Void, String > {
protected String doInBackground(Object... params) {
try {
response = CustomHttpClient.executeHttpPost(url, postParameters);
} catch (Exception e) {
System.out.println("HTTP error - " + e.toString());
}
System.out.println(response);
return response;
}
protected void onPostExecute(String result) {
dialog.dismiss();
System.out.println(result);
if (!(result == null)) {
bundle.putString("RESPONSE", result);
Intent i = new Intent(ViewDiary.this, DisplayDiary.class);
i.putExtras(bundle);
startActivity(i);
ViewDiary.this.finish();
}
else
finish();
}
}
}
Все работает, пока я не попробую связать результат с AsyncTask, когда получу нулевое выражение в строке
bundle.putString("RESPONSE", result);
Я знаю, что результат был передан методу onPostExecute, откуда берется исключение и как его исправить.
Martin