Firebase数据库getInstance崩溃应用程序

Firebase数据库getInstance崩溃应用程序

本文介绍了Firebase数据库getInstance崩溃应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建google-service.json之后运行示例时,应用程序在尝试获取SignInActivity中的数据库引用时崩溃。

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

崩溃日志

  05-21 09:27:27.644 488-488 / com.google.firebase.quickstart.database D / AndroidRuntime:关闭VM 
05-21 09:27:27.644 488-488 / com .google.firebase.quickstart.database E / AndroidRuntime:FATAL EXCEPTION:main
进程:com.google.firebase.quickstart.database,PID:488
java.lang.RuntimeException:无法启动活动ComponentInfo {com.google.firebase.quickstart.database / com.google.firebase.quickstart.database.SignInActivity}:com.google.firebase.database.DatabaseException:无法获取

FirebaseDatabase实例:FirebaseApp对象FirebaseOptions对象中没有DatabaseURL。
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)
在android.app.ActivityThread.main(ActivityThread.java:5254)$ b $在java.lang.reflect.Method.invoke(本地方法)$ b $在java.lang.reflect.Method.invoke(方法。 java:372)
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java: 698)
导致:com.google.firebase.database.DatabaseException:无法获取FirebaseDatabase实例:FirebaseApp对象的FirebaseOptions对象中没有DatabaseURL。
在com.google.firebase.database.FirebaseDatabase.getInstance(未知源)
在com.google.firebase.database.FirebaseDatabase.getInstance(未知源)
在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)
在android.app.ActivityThread.performLaunchActivity(Ac tivityThread.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)
在android.app.ActivityThread.main(ActivityThread.java:5254)
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)

如何解决这个问题?

解决方案

下载google-services.json在中的项目设置。我的错误是从下载。



浪费了很多时间:/ b

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 ?

解决方案

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

Wasted a lot of time on this :/

这篇关于Firebase数据库getInstance崩溃应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:59