I am using FirebaseAuth for user registration with email and password, and I have already added the plugin and dependencies in my project.
MainActivity.java
public class MainActivity extends AppCompatActivity implements View.OnClickListener { EditText ed_email, ed_pass; Button but_login; ProgressDialog progressDialog; FirebaseAuth firebaseAuth; Context context; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context=getApplicationContext(); FirebaseApp.initializeApp(context); firebaseAuth=FirebaseAuth.getInstance(); ed_email= (EditText) findViewById(R.id.ed_email); ed_pass= (EditText) findViewById(R.id.ed_pass); but_login= (Button) findViewById(R.id.but_login); but_login.setOnClickListener(this); progressDialog=new ProgressDialog(this); } public void registerUser(){ String email=ed_email.getText().toString().trim(); String pass=ed_pass.getText().toString().trim(); if(TextUtils.isEmpty(email)){ Toast.makeText(getApplicationContext(),"Invalid Input",Toast.LENGTH_SHORT).show(); return; } if(TextUtils.isEmpty(pass)){ Toast.makeText(getApplicationContext(),"Invalid Input",Toast.LENGTH_SHORT).show(); return; } progressDialog.setMessage("You are registering..."); progressDialog.show(); firebaseAuth.createUserWithEmailAndPassword(email,pass).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_SHORT).show(); progressDialog.hide(); } else { Toast.makeText(getApplicationContext(), "Sorry...!!!", Toast.LENGTH_SHORT).show(); progressDialog.hide(); } } }); } @Override public void onClick(View v) { registerUser(); }
}
logcat -
My App is not starting and showing the following error:
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.skapsdevelopment.firebase. Make sure to call FirebaseApp.initializeApp(Context) first.
Why is the app not starting properly?