I am trying to create user with email and password and then store their details if the task is successful in firebase database for reference purpose but I don't know what happen. The progressDialog keeps loading without creating the user. Here is the code. Please I will appreciate if anyone can put me through on it
private void registerSeller() {
String sellerName = name.getText().toString();
String phoneNumber = phone.getText().toString();
String sellerEmail = email.getText().toString();
String sellerPassword = password.getText().toString();
String sellerAddress = address.getText().toString();
if (sellerName.isEmpty()) {
name.setError("Please Enter Your Name");
`enter code here`
cancel = true;
name.requestFocus();
} else if (phoneNumber.isEmpty()) {
phone.setError("Please Enter Your Phone Number");
cancel = true;
phone.requestFocus();
} else if (sellerEmail.isEmpty()) {
email.setError("Please Enter Your Email Address");
cancel = true;
email.requestFocus();
} else if (sellerPassword.isEmpty()) {
password.setError("Please Enter Your Password");
cancel = true;
password.requestFocus();
} else if (sellerAddress.isEmpty()) {
address.setError("Please Enter Your Shop Address");
cancel = true;
address.requestFocus();
} else {
loadingDialog.setTitle("Registration Processing...");
loadingDialog.setMessage("Please wait while we are checking your credentials");
loadingDialog.setCanceledOnTouchOutside(false);
loadingDialog.show();
mAuth.createUserWithEmailAndPassword(sellerEmail, sellerPassword)
.addOnCompleteListener(new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
final DatabaseReference sellerRef = FirebaseDatabase.getInstance().getReference();
FirebaseUser user = mAuth.getCurrentUser();
String sid = mAuth.getCurrentUser().getUid();
HashMap < String, Object > sellerMap = new HashMap < > ();
sellerMap.put("sid", sid);
sellerMap.put("name", sellerName);
sellerMap.put("phone", phoneNumber);
sellerMap.put("email", sellerEmail);
sellerMap.put("password", sellerPassword);
sellerMap.put("address", sellerAddress);
sellerRef.child("sellers").child(sid)
.updateChildren(sellerMap)
.addOnCompleteListener(new OnCompleteListener < Void > () {
@Override
public void onComplete(@NonNull Task < Void > task) {
if (task.isSuccessful()) {
loadingDialog.dismiss();
Toast.makeText(SellerRegistrationActivity.this, "Seller Registered Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(SellerRegistrationActivity.this, SellerLoginActivity.class);
startActivity(intent);
} else {
loadingDialog.dismiss();
Toast.makeText(SellerRegistrationActivity.this, "Error Occurred", Toast.LENGTH_SHORT).show();
}
}
});
}
});
}
}
The first step in troubleshooting is to stop ignoring potential errors. If a Task
fails, it has an exception that explains what caused it to fail. You should log or raise that exception, to find the root cause:
mAuth.createUserWithEmailAndPassword(sellerEmail, sellerPassword)
.addOnCompleteListener(new OnCompleteListener < AuthResult > () {
@Override
public void onComplete(@NonNull Task < AuthResult > task) {
if (task.isSuccessful()) {
...
}
else {
throw task.getException();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.