简体   繁体   English

单击“创建新帐户”时,应用程序崩溃

[英]app crashes when 'create new account' is clicked

App crashes whenever I click 'create new account' button. 每当我点击“创建新帐户”按钮时,应用就会崩溃。 The error in Logcat states that I need to call FirebaseApp.initialize(this); Logcat中的错误指出我需要调用FirebaseApp.initialize(this); which I've done but still the same error occurs. 我已经完成,但仍然发生相同的错误。 Here is my RegisterActivity. 这是我的RegisterActivity。

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

And my Logcat is below. 我的Logcat在下面。

 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 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.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 android.app.Activity.performCreate(Activity.java:7136)
    at android.app.Activity.performCreate(Activity.java:7127)

Perhaps initialize Firebase at the application level, before any activities are created: 在创建任何活动之前,也许在应用程序级别初始化Firebase:

<application
    android:name="MyApp"
    [...]

public class MyApp extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FirebaseApp.initializeApp(this);
    }
}

Maybe you are misspelling something . 也许你拼错了什么。 The error says : 错误说:

FirebaseApp.initializeApp(this) 

While you are stating in the description FirebaseApp.initialize(this); 在描述中说明FirebaseApp.initialize(this);

Make sure you added this line - apply plugin: 'com.google.gms.google-services' at the end of app gradle. 确保添加了这一行-在应用gradle的末尾应用插件:“ com.google.gms.google-services”。

dependencies {
....
}
apply plugin: 'com.google.gms.google-services'

Then make a subclass extending Application class and create this Firebase instance there. 然后制作一个扩展Application类的子类,并在那里创建此Firebase实例。

public class MyApp extends Application {
@Override
public void onCreate() {
    super.onCreate();
    FirebaseApp.initializeApp(this);
 }
}

If you don't know how to make application class and its usage this post may help you. 如果您不知道如何制作应用程序类及其用法,那么本篇文章可能会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM