Hi. i was to trying login into account but whenever login button is pressed the appl forces to close and opens up again. class LoginActivity : AppCompatActivity() { var mAuth: FirebaseAuth? = null var mDatabase: DatabaseReference? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_login) mAuth = FirebaseAuth.getInstance() loginbutton.setOnClickListener { val email = emailloginET.text.toString().trim() val password = passwordloginET.text.toString().trim() if (!TextUtils.isEmpty(email) || !TextUtils.isEmpty(password)) { loginUser(email, password) } else { Toast.makeText(this, "Sorry, login failed!", Toast.LENGTH_LONG) .show() } } } private fun loginUser(email: String, password: String) { mAuth!!.signInWithEmailAndPassword(email, password) .addOnCompleteListener { task: Task -> if (task.isSuccessful) { val currentUser = mAuth!!.currentUser val userId = currentUser!!.uid mDatabase = FirebaseDatabase.getInstance().reference .child("Users").child(userId) val username = email.split("@")[0] val dashboardIntent = Intent(this, DashboardActivity::class.java) dashboardIntent.putExtra("name", username) startActivity(dashboardIntent) finish() }else { Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG) .show() } } } }