我有一个代码,我在 AsyncTask 中发出 http 请求
public class Sendcolorvalue extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onProgressUpdate(String... values) {
super.onProgressUpdate(values);
}
@Override
protected String doInBackground(String... params) {
//do your work here
HttpClient httpClient = new DefaultHttpClient();
HttpGet httpPost = new HttpGet("http://192.168.0.102/HR/index.php?command=" + command);
try {
HttpResponse response = httpClient.execute(httpPost);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
// do something with data here-display it or send to mainactivity
}
}
我想要的是从菜单项选择事件中执行它,所以我输入:
Sendcolorvalue.execute();
并出现错误:
无法从 AsyncTask 类型对非静态方法 execute(String...) 进行静态引用