数据库URL不匹配
我正在尝试将用户的数据发送到我项目的注册性数据库中。为此,我创建了一个数据库参考并复制 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要解决这个问题,只需更改
:
您需要将URL发送到getInstance()方法不是到getReferenceFromurl()方法。除此之外,您应该只使用GetReference()。
To solve this, simply change:
Into:
You need to send the URL to the getInstance() method not to the getReferenceFromUrl() method. Besides that, you should simply use getReference().
我认为这可能是因为您使用的是
getReferenceFromurl
方法。您可以尝试将URL传递到getInstance
:I think this may come because you're using the
getReferenceFromUrl
method. Can you try instead passing the URL togetInstance
: