Firebase Android – 在Kotlin中使用电子邮件和密码创建用户

我正在尝试使用Firebase和Kotlin进行注册。 看看文档,我看到了Java中的所有例子。 所以当我尝试在Kotlin中实现时,我无法使其工作。

在Java中应该是这样的:

// [START create_user_with_email] mAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { if (task.isSuccessful()) { // Sign in success, update UI with the signed-in user's information FirebaseUser user = mAuth.getCurrentUser(); } else { // If sign in fails, display a message to the user. ...... } // [START_EXCLUDE] ....... // [END_EXCLUDE] } }); // [END create_user_with_email] 

但是当我尝试像这样在kotlin中实现时:

 // [START create_user_with_email] mAuth.createUserWithEmailAndPassword(email, password) .addOnCompleteListener(this, OnCompleteListener<AuthResult> { task -> if (task.isSuccessful) { // Sign in success, update UI with the signed-in user's information val user = mAuth.currentUser } else { ...... } // [START_EXCLUDE] ..... // [END_EXCLUDE] }) // [END create_user_with_email] 

但是,这给我一个错误: 在这里输入图像描述

而我不知道如何解决它。

该示例来自: https : //github.com/firebase/quickstart-android/blob/master/auth/app/src/main/java/com/google/firebase/quickstart/auth/EmailPasswordActivity.java#L119-L137

我已经通过以下方式使用电子邮件和密码实施了Firebase注册,并且它可以正常工作:

 this.firebaseAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener { task: Task<AuthResult> -> if (task.isSuccessful) { //Registration OK val firebaseUser = this.firebaseAuth.currentUser!! } else { //Registration error } }