App crashes whenever I click 'create new account' button. The error in Logcat states that I need to call FirebaseApp.initialize(this); which I've done but still the same error occurs. Here is my 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.
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:
<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);
Make sure you added this line - apply plugin: 'com.google.gms.google-services' at the end of app gradle.
dependencies {
....
}
apply plugin: 'com.google.gms.google-services'
Then make a subclass extending Application class and create this Firebase instance there.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.