0

サーバーにデータを送信する必要があるアプリがあります。プロセスを処理する Connection クラスを作成します。以下は私のコードです:

private class Connection extends AsyncTask<ArrayList<NameValuePair>, Void, Void>{

    protected Void doInBackground(ArrayList<NameValuePair>... nameValuePairs){

        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.xxxx.com/postdata.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

         // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

            Log.i("postData", response.getStatusLine().toString());
        }
        finally{}

    }

}

ただし、「コンストラクター UrlEncodedFormEntity(ArrayList[]) は定義されていません」というエラーが表示されます。私は Android を初めて使用し、エラーの原因がわかりません。どうもありがとう!

4

1 に答える 1

1
private class Connection extends AsyncTask<ArrayList<NameValuePair>, Void, Void>{

    protected Void doInBackground(ArrayList<NameValuePair>... nameValuePairs){
        // get zero index of nameValuePairs and use that to post
        ArrayList<NameValuePair> nvPairs = nameValuePairs[0];

        try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://www.xxxx.com/postdata.php");
            httppost.setEntity(new UrlEncodedFormEntity(nvPairs));

         // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);

            Log.i("postData", response.getStatusLine().toString());
        }
        finally{}

    }

}
于 2013-07-30T15:21:20.243 に答える