Android用のアプリを作成するのは初めてで、asynctaskを初めて使用します。バックグラウンドで httppost を実行したいのですが、エラーが発生し続けます。正しいパラメーターを使用していますか? postexecute も必要ですか?
これが私のコードです
public void send(View v) { 新しい sendtask().execute(); }
private class sendtask extends AsyncTask<String,Void, String> {
String msg = msgTextField.getText().toString();
String msg1 = spinner1.getSelectedItem().toString();
String msg2 = spinner2.getSelectedItem().toString();
protected String doInBackground(String...url) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2:80/test3.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);;
nameValuePairs.add(new BasicNameValuePair("id", "12345"));
nameValuePairs.add(new BasicNameValuePair("name", msg));
nameValuePairs.add(new BasicNameValuePair("gender",msg1));
nameValuePairs.add(new BasicNameValuePair("age",msg2));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
msgTextField.setText(""); // clear text box
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
return null;