【问题标题】:cannot find symbol class OnCompleteListener找不到符号类 OnCompleteListener
【发布时间】:2019-09-16 00:19:36
【问题描述】:

我正在关注如何使用 firebase 进行注册的教程,我从 firebase 工具中复制粘贴代码,即“注册新用户”,它显示错误“错误:找不到符号类 OnCompleteListener”

我尝试根据依赖更改版本,但没有解决问题。

    mAuth.createUserWithEmailAndPassword(email, password)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>() {

                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Toast.makeText(getApplicationContext(), "Registration successful!", Toast.LENGTH_LONG).show();
                        progressBar.setVisibility(View.GONE);

                        Intent intent = new Intent(RegistrationActivity.this, LoginActivity.class);
                        startActivity(intent);
                    }
                    else {
                        Toast.makeText(getApplicationContext(), "Registration failed! Please try again later", Toast.LENGTH_LONG).show();
                        progressBar.setVisibility(View.GONE);
                    }
                }
            });

预期 android studio 可以识别符号,但它不是

【问题讨论】:

    标签: android firebase android-studio


    【解决方案1】:

    将此添加到 build.gradle (app)

    apply plugin: 'com.google.gms.google-services'
    
    android {
        ...
    }
    
    dependencies {
        ...
        implementation 'com.google.firebase:firebase-auth:16.0.3'
        implementation 'com.google.firebase:firebase-core:16.0.3'
        implementation 'com.google.android.gms:play-services-auth:15.0.1'
    }
    

    别忘了导入这个

    import com.google.android.gms.tasks.OnCompleteListener;
    

    希望对您有所帮助..

    【讨论】:

    • 感谢您的解决方案.. 还需要导入这些:import com.google.android.gms.tasks.Task; import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.FirebaseAuth;
    【解决方案2】:

    OnCompleteListener 是Play Services Task API 的一部分。您可以找到JavaDoc for that class here。从JavaDoc中看不是很清楚,但是该类的包是com.google.android.gms.tasks,您可以这样导入它:

    import com.google.android.gms.tasks.OnCompleteListener;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-01
      • 2018-09-28
      • 2019-03-24
      • 2015-03-21
      • 2018-08-09
      • 2014-06-23
      • 2017-05-07
      • 2021-08-23
      相关资源
      最近更新 更多