我正在尝试将Firebase电子邮件密码身份验证集成到我的应用程序中,但是每当我单击登录或注册时,该应用程序就会崩溃。
这是我的代码:
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.google.firebase.auth.FirebaseAuth
import kotlinx.android.synthetic.main.activity_login.*
class login : AppCompatActivity() {
private var mAuth: FirebaseAuth? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
mAuth = FirebaseAuth.getInstance()
LoginButton.setOnClickListener {
mAuth!!.signInWithEmailAndPassword(emailloginText.text.toString(),passwordLoginText.text.toString()).addOnCompleteListener {
if (it.isSuccessful){
val i= Intent(this,MainScreen::class.java)
startActivity(i)
Toast.makeText(this,"Login successful",Toast.LENGTH_LONG).show()
}
else{
Toast.makeText(this,"login Fail",Toast.LENGTH_LONG).show()
}
}
}
RegisterButton.setOnClickListener {
if(emailloginText.text.toString().isEmpty()&&passwordLoginText.text.toString().isEmpty()) {
Toast.makeText(this, "Please fill in the required fields", Toast.LENGTH_SHORT).show()
//if (editText2Pass.length() < 6) {
// Toast.makeText(getApplicationContext(), "Password must be at least 6 characters", Toast.LENGTH_SHORT).show();
} else {
mAuth!!.createUserWithEmailAndPassword(emailloginText.text.toString(), passwordLoginText.text.toString()).addOnCompleteListener {
if (it.isSuccessful) {
Toast.makeText(this, "Registration successful", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(this, "Registration Fail", Toast.LENGTH_LONG).show()
}
}
}
}
}
}