0
我使用sugarOrm並且我想用地址對象保存一個地方,當我保存所有內容都很好時,但是當我嘗試獲取地址時,它始終爲空,其他來自該地點的數據將被保存我可以得到他們,但我不知道爲什麼我不能得到我的地址對象及其信息。一對一失敗sugarOrm
我的代碼:
public class PlaceModel extends SugarRecord<PlaceModel> implements Parcelable {
@Ignore
@Expose
private ArrayList<CategoryModel> categories = new ArrayList<CategoryModel>();
@Ignore
@Expose
private ArrayList<MediaContentModel> medias = new ArrayList<MediaContentModel>();
@Ignore
@Expose
private ArrayList<ReviewContentModel> reviews = new A ArrayList<ReviewContentModel>();
@Expose
private String name;
@Expose
@Ignore
private List<Double> location = new ArrayList<Double>();
@Expose
private String website;
@Expose
private AddressModel address;
@SerializedName("global_score")
@Expose
private Integer globalScore;
@SerializedName("popularity_score")
@Expose
private Integer popularityScore;
@SerializedName("quality_score")
@Expose
private Integer qualityScore;
@Expose
@Ignore
private Object prices;
@Expose
@Ignore
private Object hours;
@Expose
@Ignore
private Object phone;
@Expose
private String createdAt;
@Expose
private String updatedAt;
@SerializedName("idObject")
@Expose
private String idPlace;
private String listCategory;
private String listMedias;
private String listReviews;
private String listLocation;
public PlaceModel() {
}
// Setters, getters and stuff for parcelable
}
地址型號:
public class AddressModel extends SugarRecord<AddressModel> implements Parcelable {
@SerializedName("street_address")
@Expose
private String streetAddress;
@SerializedName("city")
@Expose
private String city;
@SerializedName("state")
@Expose
@Ignore
private Object state;
@SerializedName("postal_code")
private String postalCode;
@SerializedName("country")
@Expose
private String country;
public AddressModel(){
}
// Setters, getters and stuff for parcelable
}
當我保存:
public void getPlaceDetails(String id)
{
RestClient client = RestClient.getInstance();
propertiesReader = new PropertiesReader(mContext);
Properties apiProperties = propertiesReader.loadPropertiesFile("api.properties");
client.createRestClient(apiProperties.getProperty("APIUrl"), mContext);
ApiManager apiManager = client.getApiManager();
PlaceModel place = apiManager.getPlaceDetails(id);
if (place != null) {
Gson gson = new GsonBuilder().create();
place.setListCategory(gson.toJsonTree(place.getCategories()).getAsJsonArray().toString());
place.setListMedias(gson.toJsonTree(place.getMedias()).getAsJsonArray().toString());
place.setListReviews(gson.toJsonTree(place.getReviews()).getAsJsonArray().toString());
place.setListLocation(gson.toJsonTree(place.getLocation()).getAsJsonArray().toString());
places.add(place);
place.save();
}
}
如果我試圖讓我的地址得到了NullPointerException
。 我跟着sugarOrm的文檔,我錯過了什麼嗎?
在此先感謝任何人。
添加您的完整代碼,您用來嘗試獲取地址。這可能是您的檢索問題。 –