我想从firebase登录,但我无法从EditText中获取值。
我的代码
var name = findViewById<EditText>(R.id.signName)
var email = findViewById<EditText>(R.id.signEmail)
var password = findViewById<EditText>(R.id.signPass)
val mEmail = email.text.toString()
val mPass = password.text.toString()
Log.d("eee", "data $mEmail $mPass")
btnOK.setOnClickListener {
var auth = FirebaseAuth.getInstance()
auth.createUserWithEmailAndPassword(mEmail, mPass)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
Log.d("sign", "create:success")
val intent = Intent(applicationContext, MainLoginActivity::class.java)
startActivity(intent)
} else {
Log.w("sign", "create:failure", task.exception)
Toast.makeText(this, "Authentication failed.", Toast.LENGTH_SHORT).show()
name.setText("")
email.setText("")
password.setText("")
name.requestFocus()
}
}
}
日志中什么都没有出现。
日志是:2020-05-17 *** Deee:数据。
错误是:java.lang.IllegalArgumentException。给定的字符串为空或无效
试着把这两行放在onClickListener里面。
mEmail = email.text.toString()
mPass = password.text.toString()