我正在尝试从 firebase 数据库的最后一个节点获取价值
我见过一些解决方案,但没有一个对我有用。
代码如下:
setData = FirebaseDatabase.getInstance().getReference().child("Questions");
Query lastQuery = setData.orderByKey().limitToLast(1);
lastQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.hasChild("JSON_OBJ")) {
SubmitKey item = dataSnapshot.getValue(SubmitKey.class);
String key2 = item.getJSON_OBJ();
} else {
Snackbar.make(findViewById(R.id.QuestionLayout), "JSON_ObJ not found", Snackbar.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
我的构造函数类
public class SubmitKey {
private String JSON_OBJ;
public SubmitKey() {
}
public SubmitKey(String JSON_OBJ) {
this.JSON_OBJ = JSON_OBJ;
}
public String getJSON_OBJ() {
return JSON_OBJ;
}
}
而不是获取值,而是转到 else 语句并显示“未找到 JSON_OBJ”。
任何帮助,将不胜感激。
编辑:我对代码进行了一些更改,现在它正在显示no setter/field found for 0-101 found on class submitKey
D/ViewRootImpl@5b51511[Questions]: ViewPostIme pointer 0
D/ViewRootImpl@5b51511[Questions]: ViewPostIme pointer 1
如果语句转到 else 语句,它也不会进入内部
守着星空守着你
相关分类