数据库URL不匹配

发布于 2025-02-09 08:03:27 字数 846 浏览 1 评论 0原文

我正在尝试将用户的数据发送到我项目的注册性数据库中。为此,我创建了一个数据库参考并复制 url 这是我的实时数据库中写的以下代码:

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/");

但是,在启动该应用程序时,我会遇到致命例外,说明以下内容:

2022-06-21 14:50:24.921 8323-8323/com.dinocodeacademy.maingoquizagain e/androidruntime:致命例外:主要例外: 过程:com.dinocodeacademy.maingoquizagain,pid:8323 java.lang.runtimeException:无法实例化活动componentInfo {com.dinocodeacademy.maingoquizagain/com.dinocodeacademy.com.signup}:com.google.fire.fire.firebase.database.database.databaseexeexection:databaseexpiption:invalid url(invalid url quiz url ur quiz url(

有人知道为什么会发生这种情况?

I'm trying to send user's data to Realtime Database in SignUpActivity in my project. For that I created a database reference and copied the url that is written in my Realtime Database with the following code:

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/");

However, when launching the app I get Fatal exception stating the following:

2022-06-21 14:50:24.921 8323-8323/com.dinocodeacademy.maingoquizagain E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dinocodeacademy.maingoquizagain, PID: 8323
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.dinocodeacademy.maingoquizagain/com.dinocodeacademy.com.SignUp}: com.google.firebase.database.DatabaseException: Invalid URL (https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/) passed to getReference(). URL was expected to match configured Database URL: https://quiz-project-6afd9-default-rtdb.firebaseio.com
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3365)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: com.google.firebase.database.DatabaseException: Invalid URL (https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/) passed to getReference(). URL was expected to match configured Database URL: https://quiz-project-6afd9-default-rtdb.firebaseio.com
at com.google.firebase.database.FirebaseDatabase.getReferenceFromUrl(FirebaseDatabase.java:214)
at com.dinocodeacademy.com.SignUp.(SignUp.java:34)
at java.lang.Class.newInstance(Native Method)
at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
at androidx.core.app.CoreComponentFactory.instantiateActivity(CoreComponentFactory.java:45)
at android.app.Instrumentation.newActivity(Instrumentation.java:1253)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3353)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
2022-06-21 14:50:24.969 8323-8323/com.dinocodeacademy.maingoquizagain I/Process: Sending signal. PID: 8323 SIG: 9

Anybody knows why that happens?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑红尘 2025-02-16 08:03:27

要解决这个问题,只需更改

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/");

DatabaseReference databaseReference = FirebaseDatabase.getInstance("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/").getReference();

您需要将URL发送到getInstance()方法不是到getReferenceFromurl()方法。除此之外,您应该只使用GetReference()。

To solve this, simply change:

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReferenceFromUrl("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/");

Into:

DatabaseReference databaseReference = FirebaseDatabase.getInstance("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/").getReference();

You need to send the URL to the getInstance() method not to the getReferenceFromUrl() method. Besides that, you should simply use getReference().

﹏半生如梦愿梦如真 2025-02-16 08:03:27

我认为这可能是因为您使用的是getReferenceFromurl方法。您可以尝试将URL传递到getInstance

DatabaseReference databaseReference = FirebaseDatabase.getInstance("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/").getReference();

I think this may come because you're using the getReferenceFromUrl method. Can you try instead passing the URL to getInstance:

DatabaseReference databaseReference = FirebaseDatabase.getInstance("https://quiz-project-6afd9-default-rtdb.europe-west1.firebasedatabase.app/").getReference();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文