单击“创建新帐户”时java应用程序崩溃
每当我单击“创建新帐户”按钮时,应用程序就会崩溃。Logcat中的错误表明我需要调用FirebaseApp。初始化(这个);我已经这么做了,但还是发生了同样的错误。这是我的注册活动
private FirebaseAuth mAuth;
private ProgressDialog loadingbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
FirebaseApp.initializeApp(this);
mAuth = FirebaseAuth.getInstance();
我的日志在下面
Process: com.example.whatsappclone, PID: 9246
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.whatsappclone/com.example.whatsappclone.RegisterActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.whatsappclone. Make sure to call FirebaseApp.initializeApp(Context) first.
at 安卓.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
at 安卓.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at 安卓.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at 安卓.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at 安卓.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at 安卓.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at 安卓.os.Handler.dispatchMessage(Handler.java:106)
at 安卓.os.Looper.loop(Looper.java:193)
at 安卓.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.安卓.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.安卓.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.whatsappclone. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common@@16.0.2:240)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source:1)
at com.example.whatsappclone.RegisterActivity.onCreate(RegisterActivity.java:36)
at 安卓.app.Activity.performCreate(Activity.java:7136)
at 安卓.app.Activity.performCreate(Activity.java:7127)
# 1 楼答案
也许你拼错了什么。错误显示:
当您在描述FirebaseApp中陈述时。初始化(这个)
# 2 楼答案
确保您添加了这一行-apply plugin:'com。谷歌。gms。谷歌服务在应用程序gradle的末尾
然后创建一个扩展应用程序类的子类,并在那里创建这个Firebase实例
如果您不知道如何创建应用程序类及其用法,此post可能会对您有所帮助
# 3 楼答案
在创建任何活动之前,可能在应用程序级别初始化Firebase: