5

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 ?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
  • 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 https://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
  • 1
    @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

3 Answers3

18

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

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
Vihaan Verma
  • 12,815
  • 19
  • 97
  • 126
  • How did you resolve this ? I've wasted a lot of time on this. Tried redownloading google-service.json to no avail – Hormigas Nov 12 '16 at 02:03
  • You have probably enabled the database after you have downloaded google-services.json. Then just download it again from the Firebase site (https://console.firebase.google.com/) – Elvis Lima Apr 23 '17 at 17:33
0

Changing google-services.json file didn't worked for me later i found out that i was using implementation 'com.google.firebase:firebase-analytics:17.5.0' implementation 'com.google.firebase:firebase-database:16.0.4' instead of implementation 'com.google.firebase:firebase-analytics-ktx:17.5.0' implementation 'com.google.firebase:firebase-database-ktx:19.4.0'

-2

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

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
colour Blue
  • 131
  • 1
  • 9