从Firebase实时数据库读取数据时发生错误。

huangapple go评论84阅读模式
英文:

Error while reading data from Firebase realtime database

问题

这是我的数据库的样子:

从Firebase实时数据库读取数据时发生错误。

这是我的代码:

DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("add_first_element").get().addOnCompleteListener(task -> {
    if (!task.isSuccessful()) {
        Log.e("firebase", "获取数据时发生错误", task.getException());
    }
    else {
        Log.d("firebase", String.valueOf(task.getResult().getValue()));
    }
});

这是Logcat告诉我的:

Firebase数据库连接被服务器强制断开。不会尝试重新连接。原因:数据库位于不同的区域。请将数据库URL更改为https://verticalrecyclerview-default-rtdb.europe-west1.firebasedatabase.app

我该如何解决这个问题?

英文:

So that's what my database looks like:
从Firebase实时数据库读取数据时发生错误。

And here's my code:

DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
    mDatabase.child("add_first_element").get().addOnCompleteListener(task -> {
        if (!task.isSuccessful()) {
            Log.e("firebase", "Error getting data", task.getException());
        }
        else {
            Log.d("firebase", String.valueOf(task.getResult().getValue()));
        }
    });

This is what logcat tells me:

> Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Database lives in a different region. Please change your database URL to https://verticalrecyclerview-default-rtdb.europe-west1.firebasedatabase.app

How do I solve this problem?

答案1

得分: 1

错误消息表明,您的 Firebase 数据库位于与 Firebase 项目的默认区域不同的区域。要解决此问题,您需要将数据库 URL 更改为正确的区域特定 URL。

在您的情况下,您需要将数据库 URL 更改为 https://verticalrecyclerview-default-rtdb.europe-west1.firebasedatabase.app。为此,您可以使用正确的 URL 更新您的 FirebaseDatabase.getInstance() 调用:

FirebaseDatabase.getInstance("https://verticalrecyclerview-default-rtdb.europe-west1.firebasedatabase.app").getReference();

这应该解决错误并允许您连接到您的 Firebase 数据库。

英文:

The error message suggests that your Firebase Database is located in a different region than the default region of your Firebase project. To resolve this issue, you need to change the database URL to the correct region-specific URL.

In your case, you need to change the database URL to https://verticalrecyclerview-default-rtdb.europe-west1.firebasedatabase.app. To do this, you can update your FirebaseDatabase.getInstance() call with the correct URL:

FirebaseDatabase.getInstance("https://verticalrecyclerview-default-rtdb.europe-west1.firebasedatabase.app").getReference();

This should resolve the error and allow you to connect to your Firebase Database.

huangapple
  • 本文由 发表于 2023年2月23日 20:37:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544947.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定