0
我不知道我的错误在这里是什么。我所有的长变量都得到0值。Firebase数据库获得儿童长期价值0通过我的班级
这是我的听众
public void onDataChange(DataSnapshot dataSnapshot) {
serviceList.clear();
for (DataSnapshot dsp : dataSnapshot.getChildren()) {
serviceList.add(dsp.getValue(Service.class)); //add result into array list
}
serviceAdapter.notifyDataSetChanged();
}
运行良好实际上是代码,当我调试,我可以看到DSP对象拥有所有我想要的值。然后,它传递给我的服务类对象,在这里它是结构:
public class Service {
private String durl;
private Boolean active;
private int poin;
private long priceShort;
private long priceMedium;
private long priceLong;
private long priceLongX;
private String name;
private String desc;
private String category;
public Service() { //default constructor
}
public Service(String name, String desc,String durl, Boolean active, String category, int poin, long priceShort, long priceMedium, long priceLong, long priceLongX) {
this.name = name;
this.desc = desc;
this.durl = durl;
this.active = active;
this.category = category;
this.priceShort = priceShort;
this.priceMedium = priceMedium;
this.priceLong = priceLong;
this.priceLongX = priceLongX;
this.poin = poin;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getDurl() {
return durl;
}
public void setDurl(String durl) {
this.durl = durl;
}
public Boolean getActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public int getPoin() {
return poin;
}
public void setPoin(int poin) {
this.poin = poin;
}
public long getPriceShort() {
return priceShort;
}
public void setPriceShort(long priceShort) {
this.priceShort = priceShort;
}
public long getPriceMedium() {
return priceMedium;
}
public void setPriceMedium(long priceMedium) {
this.priceMedium = priceMedium;
}
public long getPriceLong() {
return priceLong;
}
public void setPriceLong(long priceLong) {
this.priceLong = priceLong;
}
public long getPriceLongX() {
return priceLongX;
}
public void setPriceLongX(long priceLongX) {
this.priceLongX = priceLongX;
}
}
加入serviceList阵列后,我查了一些数组对象的价值和一切,除了我所有的长变量,如priceShort,priceMedium,priceLong好和priceLongX,所有具有0
值我做了什么:
我重新检查的价值,它的所有好分贝。
重新启动应用很多次。
编辑/ UPDATE: 这里是我的服务JSON:
"ServicesPrice" : {
"sid1" : {
"category" : "Hair-do",
"desc" : "",
"name" : "Gunting",
"poin" : 15,
"priceLong" : 0,
"priceLongx" : 0,
"priceMedium" : 0,
"priceShort" : 100000
},
"sid10" : {
"category" : "Hair-do",
"desc" : "",
"name" : "Coloring Matrix",
"poin" : 25,
"priceLong" : 525000,
"priceLongx" : 625000,
"priceMedium" : 450000,
"priceShort" : 375000
},
"sid11" : {
"category" : "Body Treatment",
"desc" : "Pijat badan 60 menit",
"name" : "Body Massage",
"poin" : 15,
"priceLong" : 0,
"priceLongx" : 0,
"priceMedium" : 0,
"priceShort" : 125000
},
"sid12" : {
"category" : "Body Treatment",
"desc" : "Massage+Lulur+Sauna+Berendam Rempah+Shampoo Loreal",
"name" : "Princess Spa",
"poin" : 25,
"priceLong" : 0,
"priceLongx" : 0,
"priceMedium" : 0,
"priceShort" : 350000
},
"sid13" : {
"category" : "Body Treatment",
"desc" : "Lulur Susu + Body Bleaching",
"name" : "Complete Whitening Milk Spa",
"poin" : 30,
"priceLong" : 0,
"priceLongx" : 0,
"priceMedium" : 0,
"priceShort" : 500000
},
再次,我可以得到所有的值惟独所有的价格
请发布您的Firebase数据库结构的屏幕截图 –
@PhanVanLinh请勿要求屏幕截图。将JSON作为文本可以更加可重用。您可以通过点击[Firebase数据库控制台](https://console.firebase.google.com/project/_/database/data)中的“导出JSON”链接来获取此信息。 –
@FrankvanPuffelen谢谢。我会在下次记得 –