gpt4 book ai didi

java - Firebase 查询方法不起作用

转载 作者:行者123 更新时间:2023-12-01 19:53:14 25 4
gpt4 key购买 nike

这是我的数据树:

"look-twopointo": {
"0" {
"comment": "Hi"
"Text1": "Hello"
"Text2": "Bonsoir"
"type": "Bonjour"
"version": "4.0.6"
}
}

由于某种原因,查询不起作用。

button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mDatabase = FirebaseDatabase.getInstance().getReference().child("0");// pay attention to the this path reference
// Read from the database
Query query = mDatabase.child("version")/*.orderByChild("Text1")*/.equalTo("4.0.6")/*.startAt("d")/*.endAt("Dude")*/;
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
//String value = dataSnapshot.getValue(String.class); //these three lines below are probably the problem
String value = (String) dataSnapshot.getValue();
System.out.println(value);
Text.setText(value);
}

以下是系统输出的内容:

D/ViewRootImpl: ViewPostImeInputStage processPointer 0
D/ViewRootImpl: ViewPostImeInputStage processPointer 1
I/DynamiteModule: Considering local module
com.google.android.gms.firebase_database:4 and remote module
com.google.android.gms.firebase_database:6
Selected remote version of
com.google.android.gms.firebase_database, version >= 6
D/ResourcesManager: For user 0 new overlays fetched Null
W/System: ClassLoader referenced unknown path:
/data/data/com.google.android.gms/app_chimera/m/0000005e/n/armeabi-v7a
ClassLoader referenced unknown path:
/data/data/com.google.android.gms/app_chimera/m/0000005e/n/armeabi
D/ResourcesManager: For user 0 new overlays fetched Null
I/System.out: null

不知道是不是因为我用的是手机,没有下载并在模拟器上试用。我需要设置什么才能在手机上查询吗?

这可能是导致此问题的错误

05-28 17:12:42.743 2449-3078/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'LABEL' not found
NetlinkEvent::FindParam(): Parameter 'UID' not found

或者我就是这样

W/System: ClassLoader referenced unknown path: 
/data/data/com.google.android.gms/app_chimera/m/0000005e/n/armeabi-v7a
ClassLoader referenced unknown path:
/data/data/com.google.android.gms/app_chimera/m/0000005e/n/armeabi

我希望它输出 4.0.6。

更新:我实际上找不到错误。它无缘无故地输出 null

最佳答案

要解决此问题,您需要将查询更改为:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.orderByChild("version").equalTo("4.0.6");

并且将返回所有 version 属性等于 4.0.6 的记录。

关于java - Firebase 查询方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50549123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com