I'm sending some data from my app to an external server.
public class PostKey extends AsyncTask<String, String, String> {
public AsyncResponse delegate = null;
@Override
protected String doInBackground(String... params) {
postData(params[0]);
return null;
}
@Override
protected void onPostExecute(String result){
Log.d(String.valueOf(result), " Result?");
delegate.processFinish(result); // Returns NullPointerException
}
public void postData(String valueIWantToSend) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://domain.com/post.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("hoi", "test"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String responseStr = EntityUtils.toString(response.getEntity());
Log.d(responseStr, "");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
public interface AsyncResponse {
void processFinish(String output);
}
}
Log.d(responseStr, "");
does return true or false, depending on what data was send, and logs it.
delegate.processFinish(result);
returns the NullPointerException also mentioning public class PostKey extends AsyncTask<String, String, String>
eventhough all the parameters are declared as Strings
.
I've also tried replacing result
with responseStr
but that didn't work either.