Firebase database getInstance crashes app


Firebase database getInstance crashes app



When running the sample after creating google-service.json, the app crashes when trying to get database reference in SignInActivity


mDatabase = FirebaseDatabase.getInstance().getReference();



Crash log


05-21 09:27:27.644 488-488/com.google.firebase.quickstart.database D/AndroidRuntime: Shutting down VM
05-21 09:27:27.644 488-488/com.google.firebase.quickstart.database E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.google.firebase.quickstart.database, PID: 488
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.firebase.quickstart.database/com.google.firebase.quickstart.database.SignInActivity}: com.google.firebase.database.DatabaseException: Failed to get

FirebaseDatabase instance: FirebaseApp object has no DatabaseURL in its FirebaseOptions object.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: com.google.firebase.database.DatabaseException: Failed to get FirebaseDatabase instance: FirebaseApp object has no DatabaseURL in its FirebaseOptions object.
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
at com.google.firebase.quickstart.database.SignInActivity.onCreate(SignInActivity.java:39)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)



How to fix this issue ?





Check if the google-service.json contains the url of your database.
– Gabriele Mariotti
May 21 '16 at 15:22





@GabrieleMariotti googl-services.json generation link developers.google.com/mobile/add doesn't seem to be doing anything related to firebase
– Vihaan Verma
May 21 '16 at 16:46





Inside the file you should have something like: "project_info": { "project_number": "xxxxxxx", "firebase_url": "https://yourname-xxx.firebaseio.com",....
– Gabriele Mariotti
May 21 '16 at 16:48


"project_info": { "project_number": "xxxxxxx", "firebase_url": "https://yourname-xxx.firebaseio.com",....





@GabrieleMariotti thanks you pointed me out in the right direction. I was download the wrong google-services.json file from developers.google.com/mobile/add instead of firebase project.
– Vihaan Verma
May 21 '16 at 17:13




2 Answers
2



Download google-services.json from Project Settings in the Firebase console. My mistake was downloading it from https://developers.google.com/mobile/add.





How did you resolve this ? I've wasted a lot of time on this. Tried redownloading google-service.json to no avail
– Anant
Nov 12 '16 at 2:03





You have probably enabled the database after you have downloaded google-services.json. Then just download it again from the Firebase site (console.firebase.google.com)
– Elvis Lima
Apr 23 '17 at 17:33



mFirebaseDatabaseReference = database.getInstance().getReference("root-element in firebase");


mFirebaseDatabaseReference = database.getInstance().getReference("root-element in firebase");



When you call getReference you need to provide a URL. If your project is bound already in Firebase with the database you have created, use the root element of the data in Firebase as the parameter to getReference().


getReference


getReference()






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Possible Unhandled Promise Rejection (id: 0): ReferenceError: user is not defined ReferenceError: user is not defined

Opening a url is failing in Swift