我正在开发一个社交媒体类型的应用程序,它也具有Firebase连接。突然我收到此错误:
无法解析方法.addOnCompleteListener()。
我尝试使缓存无效并重新启动,重新构建项目,再次同步项目,还删除了.gradle文件夹中的内容,并且未进行任何重建。
这些是一些项目文件的图像,如果需要,我可以提供更多。
RegisterActivity.java RegisterActivity.java
RegisterActivity.java导入区域 RegisterActivity.java import area
build.gradle(模块应用) build.gradle(module app)
build.grale(项目) build.grale(project)
RegisterActivity.java的代码
package com.socialnetwork.socialnet;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.ProgressDialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
public class RegisterActivity extends AppCompatActivity
{
private EditText UserEmail, UserPassword, UserConfirmPassword;
private Button CreateAccountButton;
private ProgressDialog loadingBar;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
UserEmail = (EditText) findViewById(R.id.register_email);
UserPassword = (EditText) findViewById(R.id.register_password);
UserConfirmPassword = (EditText) findViewById(R.id.register_confirm_password);
CreateAccountButton = (Button) findViewById(R.id.register_create_account);
loadingBar = new ProgressDialog(this);
CreateAccountButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view)
{
CreateNewAccount();
}
});
}
private void CreateNewAccount()
{
String email = UserEmail.getText().toString();
String password = UserPassword.getText().toString();
String confirmPassword = UserConfirmPassword.getText().toString();
if(TextUtils.isEmpty(email))
{
Toast.makeText(this, "Please write your email...", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(password))
{
Toast.makeText(this, "Please write your password...", Toast.LENGTH_SHORT).show();
}
else if(TextUtils.isEmpty(confirmPassword))
{
Toast.makeText(this, "Please confirm your password...", Toast.LENGTH_SHORT).show();
}
else if(!password.equals(confirmPassword))
{
Toast.makeText(this, "your password do not match with your confirm password...", Toast.LENGTH_SHORT).show();
}
else
{
loadingBar.setTitle("Creating New Account");
loadingBar.setMessage("Please wait, while we are creating your new Account...");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task)
{
if(task.isSuccessful())
{
SendUserToSetupActivity();
Toast.makeText(RegisterActivity.this, "you are authenticated successfully...", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
else
{
String message = task.getException().getMessage();
Toast.makeText(RegisterActivity.this, "Error Occured: " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
private void SendUserToSetupActivity()
{
Intent setupIntent = new Intent(RegisterActivity.this, SetupActivity.class);
setupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(setupIntent);
finish();
}
}
答案 0 :(得分:0)
您缺少this
关键字。试试
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
....
}
检查Set up Firebase Authentication for Android的“注册新用户”部分,您将看到丢失的地方
或尝试
我已经检查了您的代码和我的代码之间的区别,唯一重要的区别是我在其中实现的应用build.gradle文件中
implementation 'com.google.firebase:firebase-core:16.0.1'
而你没有。 尝试实施。