android - 在 Android Studio 中运行时,Android 应用程序停止在模拟器上运行
问题描述
大家好,我正在尝试将 firebase 添加到我的应用程序中,但在运行时停止在 Emulator 上工作
我的日志:
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)
解决方案
首先尝试使用支持的模拟器google-play-services
,检查这个
同样正如崩溃所解释的,请尝试致电
FirebaseApp.initializeApp(Context)
在你的活动中使用firebase实例之前,你可以在你的Application
类onCreate
方法中这样:
FirebaseApp.initializeApp(getBaseContext())
并确保您正确应用最新 google-play-services
插件
推荐阅读
- android - Jetpack Compose 无限重复,重复 startDelay
- python - 使用 Python 同时发送多个 API 请求
- sql - 查找列中行的差异
- windows - Jenkins 的 Windows 资源管理器无法启动
- spring - 无法从在 K8 中运行的 Spring Boot 应用程序连接到 Google Cloud MySQL DB
- c++ - 构造函数 - 复制常量引用 VS 移动复制值
- java - 我应该如何在 Java 中获得结果使用流?
- python - 如何安排脚本每天在 jupyter notebook 上运行?
- r - Shiny App中反应式条形图的问题
- compiler-errors - 编译错误:collect2.exe:错误:ld 返回 1 退出状态