Android 获得';无法解析方法';addOnCompletionListener()';试图在builder.setPositiveButton';s onClick()方法

Android 获得';无法解析方法';addOnCompletionListener()';试图在builder.setPositiveButton';s onClick()方法,android,firebase,android-alertdialog,firebase-authentication,Android,Firebase,Android Alertdialog,Firebase Authentication,我试图在AlertDialog.Builder的Builder.setPositiveButton方法中放置一些代码 问题是我遇到了以下错误:无法解析方法addOnCompletionListener(anonymous android.content.DialogInterface.OnClickListener,anonymous com.google.android.gms.tasks.OnCompletionListener) 代码如下: AlertDialog.Builder

我试图在
AlertDialog.Builder
Builder.setPositiveButton
方法中放置一些代码

问题是我遇到了以下错误:
无法解析方法addOnCompletionListener(anonymous android.content.DialogInterface.OnClickListener,anonymous com.google.android.gms.tasks.OnCompletionListener)

代码如下:

    AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
                builder.setTitle("Title");
                builder.setView(R.layout.customlayout);
                builder.setPositiveButton("Continue", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

//error from below line

                   mAuth.createUserWithEmailAndPassword(userEmail.getText().toString(), userPassword.getText().toString())
                                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                                    @Override
                                    public void onComplete(@NonNull Task<AuthResult> task) {
                                        Log.d("signUpSuccessful", "createUserWithEmail:onComplete:" + task.isSuccessful());

                                        // If sign in fails, display a message to the user. If sign in succeeds
                                        // the auth state listener will be notified and logic to handle the
                                        // signed in user can be handled in the listener.
                                        if (!task.isSuccessful()) {
                                            Snackbar snackbar = Snackbar
                                                    .make(coordinatorLayout, "Sign up failed. Please retry.", Snackbar.LENGTH_SHORT);
                                            snackbar.show();
                                        }

                                        // ...
                                    }
                                });

//upto this line
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.show();
AlertDialog.Builder=新建AlertDialog.Builder(SignUpActivity.this);
建造商名称(“名称”);
builder.setView(R.layout.customlayout);
setPositiveButton(“继续”,新建DialogInterface.OnClickListener()){
@凌驾
公共void onClick(DialogInterface,inti){
//下线错误
mAuth.createUserWithEmailAndPassword(userEmail.getText().toString(),userPassword.getText().toString())
.addOnCompleteListener(这是新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
Log.d(“signUpSuccessful”,“createUserWithEmail:onComplete:”+task.isSuccessful());
//如果登录失败,则向用户显示消息。如果登录成功
//将通知身份验证状态侦听器,并使用逻辑来处理
//可以在侦听器中处理已登录用户。
如果(!task.issusccessful()){
Snackbar Snackbar=Snackbar
.make(coordinatorLayout,“注册失败,请重试”,Snackbar.LENGTH\u SHORT);
snackbar.show();
}
// ...
}
});
//一直到这条线
}
});
AlertDialog=builder.create();
dialog.show();
这里怎么了

请让我知道。

添加OnCompleteListener(这是新的OnCompleteListener()
addOnCompleteListener(this, new OnCompleteListener<AuthResult>()
这一行中的“this”表示您的DialogInterface.OnClickListener,您应该检查此方法需要什么类型的参数,如果是上下文,请尝试将其更改为

addOnCompleteListener(YourActivityName.this, new OnCompleteListener<AuthResult>()
addOnCompleteListener(YourActivityName.this,新的OnCompleteListener()
添加OnCompleteListener(这是新的OnCompleteListener()
这一行中的“this”表示您的DialogInterface.OnClickListener,您应该检查此方法需要什么类型的参数,如果是上下文,请尝试将其更改为

addOnCompleteListener(YourActivityName.this, new OnCompleteListener<AuthResult>()
addOnCompleteListener(YourActivityName.this,新的OnCompleteListener()

您的问题发生在以下代码行:

.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

使用
ActivityName代替
使用
ActivityName。此

您的问题发生在以下代码行:

.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

除了
这个
使用
活动名。这个

很好,我完全复制了谷歌文档的内容。;)很好,我完全复制了谷歌文档的内容。;)