Aydomir
Aydomir

Reputation: 13

POST Request error in AsyncTask

I call like this:

new asyncTaskPost().execute();

This is my AsyncTask:

class asyncTaskPost extends AsyncTask<String, Void, Void> {

@Override
protected void onPreExecute() {
}

@Override
protected Void doInBackground(String... params) { <------ HERE ERROR!!!!!!
postMethod();
}

@Override
protected void onPostExecute(Void result) {
}

}

And that POST Request:

public static void postMethod()
{

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://iwindroids.ru/test.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

nameValuePairs.add(new BasicNameValuePair("lal", "ss"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response= httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
String serverResponse = EntityUtils.toString(responseEntity);
Log.i("server response is="+serverResponse,"");

} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
}
}

Prompt in what a problem protected Void doInBackground(String... params) { and how to fix it? I have marked an error in the code

<------ HERE ERROR!!!!!!

Thank you!

Upvotes: 1

Views: 48

Answers (1)

Raghunandan
Raghunandan

Reputation: 133560

There is nothing passed to doInbackground and also you need a return statement

@Override
protected Void doInBackground(Void... params) {
postMethod();
return null;
}

Also change

class asyncTaskPost extends AsyncTask<Void, Void, Void> {

Params, the type of the parameters sent to the task upon execution.

Check AsyncTask generic types @

http://developer.android.com/reference/android/os/AsyncTask.html

Upvotes: 3

Related Questions