我創建了一個名爲Placeslist類列表保存時,我儘量讓Placeslist的列表,並在其保存的對象,我得到Android.java.lang.NullPointerException 這是placeslist類異常而
public class Placeslist {
@Key
public String status;
@Key
public String id;
@Key
public String name;
@Key
public String reference;
@Key
public double lat;
@Key
public double lon;
public Placeslist(String status,String id,String name,String reference,double lat,double lon) {
// TODO Auto-generated constructor stub
this.status=status;
this.id=id;
this.name=name;
this.reference=reference;
this.lat=lat;
this.lon=lon;
}
,這是代碼當我嘗試保存對象列表中的
Placeslist placeslist=null;
String data = EntityUtils.toString(response.getEntity());
JSONObject jsonObj = new JSONObject(data);
List<Placeslist>places=null;
JSONArray results = jsonObj.getJSONArray("results");
for (int i = 0; i < results.length(); i++) {
JSONObject result = results.getJSONObject(i);
String name = result.getString("name");
String id = result.getString("id");
String reference = result.getString("reference");
JSONObject latitudes = result.getJSONObject("geometry")
.getJSONObject("location");
double lon = latitudes.getDouble("lng");
double lat = latitudes.getDouble("lat");
placeslist=new Placeslist("OK", id, name, reference, lat, lon);
places.add(placeslist);
}
使用調試併發布你有NullPointerException的行。 – Marckaraujo
還有一個關於你的設計的評論:或許你需要將'Placeslist'類重命名爲'Place'。 – iCantSeeSharp
@Souvlaki謝謝我將更新它 – user1115684