我这样称呼:
new asyncTaskPost().execute();
这是我的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) {
}
}
那个POST请求:
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) {
}
}
提示问题protected Void doInBackground(String... params) {
以及如何解决问题?我在代码中标记了一个错误
&lt; ------ HERE ERROR !!!!!!
谢谢!
答案 0 :(得分:3)
没有任何内容传递给doInbackground
,您还需要一个返回语句
@Override
protected Void doInBackground(Void... params) {
postMethod();
return null;
}
同时更改
class asyncTaskPost extends AsyncTask<Void, Void, Void> {
Params,执行时发送给任务的参数类型。
检查AsyncTask泛型类型@
http://developer.android.com/reference/android/os/AsyncTask.html