首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Firebase查询方法不起作用

Firebase查询方法不起作用
EN

Stack Overflow用户
提问于 2018-05-27 12:55:58
回答 1查看 375关注 0票数 0

这是我的数据树:

"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

EN

回答 1

Stack Overflow用户

发布于 2018-05-27 15:00:02

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

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

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50549123

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档