我创建了一个名为 Placeslist 的类,当我尝试创建 Placeslist 列表并将对象保存在其中时,我得到了Android.java.lang.NullPointerException This is 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);
}