【问题标题】:Why Can't read data From Database Firebase?为什么无法从数据库 Firebase 中读取数据?
【发布时间】:2021-11-26 18:43:58
【问题描述】:
 mFirebaseInstance = FirebaseDatabase.getInstance();

        mFirebaseDatabase = mFirebaseInstance.getReference("Name");


        mFirebaseInstance.getReference("Name2").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Log.e(TAG, "App title updated");

                 appTitle = dataSnapshot.getValue(String.class);


                // update toolbar title

                textGrid.setText(appTitle);
                if (appTitle == "tt"){
                    Toast.makeText(getApplicationContext() ,"dsfsdf",Toast.LENGTH_LONG).show();
                }


            }

            @Override
            public void onCancelled(DatabaseError error) {
                // Failed to read value
                Log.e(TAG, "Failed to read app title value.", error.toException());
                Toast.makeText(getApplicationContext() ,"Error read Value",Toast.LENGTH_LONG).show();

            }
        });

我存储了几天前工作的名称信息,这些信息存储在 firebase Realtime 上,现在你不这样做了 它,没有任何东西进入数据库。

在我使用的依赖项中

implementation 'com.google.firebase:firebase-database:20.0.2'

并在构建 Gradle(项目)

 dependencies {

        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
        classpath 'com.google.firebase:perf-plugin:1.3.1'
        classpath 'com.android.tools.build:gradle:4.0.0'
        classpath 'com.google.gms:google-services:4.3.0'
        classpath 'com.google.gms:google-services:2.0.0-alpha2'



    }

【问题讨论】:

  • 您的项目是否已连接到 Firebase?
  • 是连接。
  • 可能是您不小心删除了您的 google-services.json?还是更改了您的 SHA-1?
  • 还有 mFirebaseInstance.getReference("Name2") 应该是 mFirebaseInstance.child("Name2")
  • 尝试检查您的 Firebase 规则是否已更新(允许访问数据库)。

标签: java firebase android-studio


【解决方案1】:

在 cmets 中我们发现一个问题,你需要添加另一个 SHA-1,或者更改现有的。转到您的项目。然后点击您的项目并转到设置。在底部,点击添加新指纹,或删除

【讨论】:

  • 我这样做了,但不工作
  • 检查您在数据库中的权限
  • 这是怎么做到的...?
  • { "rules": { ".read": true, ".write": true } }
  • 但是在你的代码中,你没有设置任何数据,只是得到
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-13
相关资源
最近更新 更多