Ich stehe ein Problem mit BasicNameValuePair. Ich möchte eine ArrayList in BasicNameValuePair übergeben. Durch NameValuePair möchte ich diese arrayList in eine PHP-Datei hochladen. Aber ich bekomme einen Fehler. Bitte hilf mir. Vielen Dank.Wie ArrayList <string> in BasicNameValuePair übergeben
Hier ist mein Android-Code:
protected String doInBackground(String... params) {
InputStream inputStream = null;
String result = null;
Intent in = getIntent();
String city = in.getStringExtra(("city"));
ArrayList<String> category = in.getStringArrayListExtra("category"); **//Here i am passing multiple value of category.**
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("city", city));
nameValuePairs.add(new BasicNameValuePair("category", category)); **//Here error is coming(BasicNameValuePair cannot applied to <string, java.util.ArrayList<java.lang.String>)**
DefaultHttpClient httpClient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://10.0.2.2/qsearch.php");
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
}
catch(Exception e){
e.printStackTrace();
}
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (inputStream != null) inputStream.close();
} catch (Exception squish) {
}
return result;
}
}
@Override
protected void onPostExecute(String result){
myJSON=result;
showList();
}
}
GetDataJSON g=new GetDataJSON();
g.execute();
Überprüfen Sie [diese] (http://stackoverflow.com/questions/21131015/how-to-send-a-string-array-as-basic-name-value-pair-as-httppost) – Raghavendra
Sie sollten nicht Verwenden Sie HttpClient, HttpPost, NameValuePair, ect. http://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client – Massimo