我從我的數據庫中檢索有關位置的信息。在取回它們之後,我想將它們存儲到一個ArrayList(它是「地址的ArrayList」),但是,每次寫入新條目時,它都會覆蓋之前的條目。我正在通過打印日誌來測試它。是代碼段:Android:ArrayList舊條目被新條目覆蓋
response = CustomHttpClient.executeHttpPost("http://www.testing.com
/requestPlaces.php", postParameters);
JSONArray jArray = new JSONArray(response);
for(int i = 0; i < jArray.length() ; i++)
{
Places place = new Places();
JSONObject jObj = jArray.getJSONObject(i);
place.setPlace(
jObj.optString("placeID"),
jObj.optString("placeName"),
jObj.optString("placeType"),
jObj.optString("placeLat"),
jObj.optString("placeLng"),
jObj.optString("placePict"),
jObj.optString("placeRegion"));
arrPlace.add(place);
for(int j = 0; j <= i ; j++)
{
Log.e("log_tag2", arrPlace.get(j).getPlaceID());
}
這是我的日誌打印出來,顯示了前一個條目已被覆蓋:
02-22 16:30:26.538: E/log_tag2(6148): p0001
02-22 16:30:26.538: E/log_tag(6148): p0002
02-22 16:30:26.538: E/log_tag2(6148): p0002
02-22 16:30:26.538: E/log_tag2(6148): p0002
02-22 16:30:26.538: E/log_tag(6148): p0003
02-22 16:30:26.538: E/log_tag2(6148): p0003
02-22 16:30:26.538: E/log_tag2(6148): p0003
02-22 16:30:26.538: E/log_tag2(6148): p0003
02-22 16:30:26.538: E/log_tag(6148): p0004
02-22 16:30:26.538: E/log_tag2(6148): p0004
02-22 16:30:26.538: E/log_tag2(6148): p0004
02-22 16:30:26.538: E/log_tag2(6148): p0004
02-22 16:30:26.538: E/log_tag2(6148): p0004
它似乎是setPlace方法的某種問題,或者是由此方法寫入的屬性範圍。你能否添加Places類代碼? – 2012-02-22 08:46:59
謝謝,它解決了。愚蠢的小東西!大聲笑。 – DroidMatt 2012-02-22 08:48:50