Skip to content
Advertisement

Database URL do not match

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?

Advertisement

Answer

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().

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement