英文:
Error while reading data from Firebase realtime database
问题
这是我的数据库的样子:
这是我的代码:
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:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论