在Android Studio中运行时,Android应用程序无法在模拟器上运行

时间:2019-03-21 09:25:44

标签: android firebase firebase-realtime-database

大家好,我正在尝试将Firebase添加到我的应用中,但是在运行时停止在模拟器上工作

我的日志:

03-21 09:14:40.581 6568-6568/com.example.fireproject E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.fireproject, PID: 6568
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.fireproject. Make sure to call FirebaseApp.initializeApp(Context) first.
    at com.google.firebase.FirebaseApp.getInstance(SourceFile:218)
    at com.google.firebase.database.FirebaseDatabase.getInstance(Unknown Source)
    at com.example.fireproject.MainActivity$1.onClick(MainActivity.java:31)
    at android.view.View.performClick(View.java:4756)
    at android.view.View$PerformClick.run(View.java:19749)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    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:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

1 个答案:

答案 0 :(得分:0)

首先尝试使用以google-play-services为后盾的模拟器,然后选中this


还如崩溃所解释的那样,尝试致电

FirebaseApp.initializeApp(Context)

在活动中使用Firebase实例之前,您可以在ApplicationonCreate方法中执行以下操作:

FirebaseApp.initializeApp(getBaseContext())

并确保您正确应用最新 google-play-services插件