- Forum-Beiträge: 1
05.06.2015, 10:32:50 via Website
05.06.2015 10:32:50 via Website
Hallo,
immer wenn ich in meiner ListView ein Item auswähle strützt die App ab.
Fehlercode:
06-05 10:30:58.078: E/AndroidRuntime(13086): at de.einkaufsliste.JSONParser.makeHttpRequest(JSONParser.java:62)
06-05 10:30:58.078: E/AndroidRuntime(13086): at de.einkaufsliste.EditEinkauf$GetEinkaufDetails$1.run(EditEinkauf.java:97)
In der JSONParser Class ist es dieser Abschnitt:
try {
if (method == "POST") {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} else if (method == "GET") {
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
in der Main der Abschnitt:
protected String doInBackground(String... params) {
runOnUiThread(new Runnable() {
@Override
public void run() {
int success;
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("pid", pid));
JSONObject json = jsonParser.makeHttpRequest(
url_einkauf_details, "GET", params);
Log.d("Einkauf", json.toString());
success = json.getInt(TAG_SUCCESS);
System.out.println("success" + success);
if (success == 1) {
JSONArray einkaufObj = json
.getJSONArray(TAG_EINKAUF);
JSONObject einkauf = einkaufObj.getJSONObject(0);
txtAnzahl = (EditText) findViewById(R.id.anzahlEdit);
txtBeschreibung = (EditText) findViewById(R.id.beschreibungEdit);
txtSupermarkt = (EditText) findViewById(R.id.supermarktEdit);
txtAnzahl.setText(einkauf.getString(TAG_ANZAHL));
txtBeschreibung.setText(einkauf
.getString(TAG_BESCHREIBUNG));
txtSupermarkt.setText(einkauf
.getString(TAG_SUPERMARKT));
} else {
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
return null;
Vielleicht könnt ihr mir ja weiter helfen
Vielen Dank schonmal und Gruß
Moritz