![](/img/trans.png)
[英]How to find if a child with particular value in its fields exists in Firebase?
[英][SOLVED]Firebase returns null value for a particular child even if it exists
[EDIT]问题出在我的ComRec类上。 getKoil方法由于某些原因而无法使用。我使用studio生成了该方法,现在可以正常使用了。感谢帮助人员。[编辑]我有一个ComRec类,用于存储某些佣金值。 在计算器中,我输入了一些值并执行了一些操作,然后将其存储在Firebase中的特定用户下。 然后,我用ComRec对象的值创建一个pdf表。 但是我的问题是成员“ koil”即使在ComRec对象中也显示了null值。
public class ComRec {
private Double freeRation;
private Double npnsRice;
private Double npsRice;
private Double phhRice;
private Double aayRice;
private Double npnsWheat;
private Double phhWheat;
private Double aayWheat;
private Double atta;
private Double total;
private Double koil;
private Double sugar;
private Double totalCommission;
public ComRec(){
}
public ComRec(Double freeRation, Double npnsRice, Double npsRice, Double phhRice, Double aayRice, Double npnsWheat, Double phhWheat, Double aayWheat, Double atta, Double total, Double koil, Double sugar , Double totalCommission) {
this.freeRation = freeRation;
this.npnsRice = npnsRice;
this.npsRice = npsRice;
this.phhRice = phhRice;
this.aayRice = aayRice;
this.npnsWheat = npnsWheat;
this.phhWheat = phhWheat;
this.aayWheat = aayWheat;
this.atta = atta;
this.total = total;
this.koil = koil;
this.sugar = sugar;
this.totalCommission = totalCommission;
}
用户类别
public class User {
private String UID;
private String ardNo;
private String email;
private String serialKey;
private String taluk;
private ComRec C;
public User(){
}
public User(String UID, String ardNo, String email, String serialKey,String taluk) {
this.UID = UID;
this.ardNo = ardNo;
this.email = email;
this.serialKey = serialKey;
this.taluk = taluk;
this.C = null;
}
public User(String UID, String ardNo, String email, String serialKey,String taluk,ComRec C) {
this.UID = UID;
this.ardNo = ardNo;
this.email = email;
this.serialKey = serialKey;
this.taluk = taluk;
this.C = C;
}
public String getUID() {
return UID;
}
public void setUID(String UID) {
this.UID = UID;
}
public String getArdNo() {
return ardNo;
}
public void setArdNo(String ardNo) {
this.ardNo = ardNo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getSerialKey() {
return serialKey;
}
public void setSerialKey(String serialKey) {
this.serialKey = serialKey;
}
public String getTaluk() {
return taluk;
}
public void setTaluk(String taluk) {
this.taluk = taluk;
}
public ComRec getComRec() {
return C;
}
public void setComRec(ComRec c) {
C = c;
}
}
这是我的火力基地数据,您可以看到koil = 172.5:
其他所有成员均给出正确的值,但有误
这是通过从User类获取ComRec对象的方法
根据您的数据库结构,您可以使用它来获取Koil
DatabaseReference reff = FirebaseDatabase.getInstance().getReference("User");
reff.child(user.getUid()).child("comRec").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot:dataSnapshot.getChildren()){
ComRec com = snapshot.getValue(ComRec.class);
Double Koil = com.getkoil();
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.