作为标题,这段代码给了我错误
mAuth.createUserWithEmailAndPassword(userId + "@gmail.com", userPw)
.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
Log.d("signup: ", "createUserWithEmail:success");
FirebaseUser user = mAuth.getCurrentUser();
// updateUI(user);
} else {
// If sign in fails, display a message to the user.
Log.w("signup: ", "createUserWithEmail:failure", task.getException());
Toast.makeText(view.getContext(), "Authentication failed.",
Toast.LENGTH_SHORT).show();
// updateUI(null);
}
// ...
}
});
是的,我将其复制到某个地方,但仍然给我错误:
错误:找不到适用于addOnCompleteListener(,>)的方法 方法Task.addOnCompleteListener(Executor,OnCompleteListener)不适用 (参数不匹配;无法转换为执行器) 方法Task.addOnCompleteListener(Activity,OnCompleteListener)不适用 (参数不匹配;无法转换为活动)
我的build.gradle供参考
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "xxx.xx.xxx"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation 'androidx.annotation:annotation:1.0.2'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'androidx.fragment:fragment:1.0.0'
}
apply plugin: 'com.google.gms.google-services'