this is my register activity class code anyone help me to fix and find error on this code and tell me please
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
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;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class RegisterActivity extends AppCompatActivity {
private Button CreateAccountButton;
private EditText UserEmail, UserPassowrd;
private TextView AlreadyHaveAccountLink;
private FirebaseAuth mAuth;
private DatabaseReference RootRef;
private static long back_pressed;
private static int Time_Delay = 2000;
private ProgressDialog loadingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mAuth = FirebaseAuth.getInstance();
RootRef = FirebaseDatabase.getInstance().getReference();
InitializeFileds();
AlreadyHaveAccountLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SendUserToLoginActivity();
}
});
CreateAccountButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CreateNewAccount();
}
});
}
private void CreateNewAccount() {
String email = UserEmail.getText().toString();
String password = UserPassowrd.getText().toString();
if (TextUtils.isEmpty(email)) {
Toast.makeText(this, "Please Enter Email...", Toast.LENGTH_SHORT).show();
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(this, "Please Enter Password...", Toast.LENGTH_SHORT).show();
} else {
loadingBar.setTitle("Creating New Account");
loadingBar.setMessage("PLease Wait, while we were creating new account for you...");
loadingBar.setCanceledOnTouchOutside(true);
loadingBar.show();
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
String currentUserID = mAuth.getCurrentUser().getUid();
RootRef.child("Users").child(currentUserID).setValue("");
SendUserToMainActivity();
Toast.makeText(RegisterActivity.this, "Account Created Successfully...", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
} else {
String message = task.getException().toString();
Toast.makeText(RegisterActivity.this, "Error : " + message, Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
private void InitializeFileds() {
CreateAccountButton = (Button) findViewById(R.id.register_button);
UserEmail = (EditText) findViewById(R.id.register_email);
UserPassowrd = (EditText) findViewById(R.id.register_password);
AlreadyHaveAccountLink = (TextView) findViewById(R.id.already_account_have_link);
loadingBar = new ProgressDialog(this);
}
private void SendUserToLoginActivity() {
Intent loginIntent = new Intent(RegisterActivity.this, LoginActivity.class);
startActivity(loginIntent);
}
private void SendUserToMainActivity() {
Intent mainIntent = new Intent(RegisterActivity.this, MainActivity.class);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mainIntent);
finish();
}
@Override
public void onBackPressed() {
if (back_pressed + Time_Delay > System.currentTimeMillis()) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
} else {
Toast.makeText(this, "Press again to exit", Toast.LENGTH_SHORT).show();
}
back_pressed = System.currentTimeMillis();
}
}