-1

I was trying to set Toast, to show is registratiion was succesful of failed. But couldn't make it resolve the context. There is the code:

private void RegisterAccount() {
        String username = RegisterUsername.getText().toString();
        String mail = RegisterMail.getText().toString();
        String password = RegisterPassword.getText().toString();

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

                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {

                    if (task.isSuccessful()) {

                        User user = new User(username, mail);

                        FirebaseDatabase.getInstance().getReference("Users")

                                .child(FirebaseAuth.getInstance().getCurrentUser().getUid())

                                .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() {

                            @Override
                            public void onComplete(@NonNull Task<Void> task) {

                                if (task.isSuccessful()) {
                                    Toast.makeText(RegisterAccount.this, "Success", Toast.LENGTH_LONG).show();
                                }

                                else {
                                    Toast.makeText(RegisterAccount.this, "Failed", Toast.LENGTH_LONG).show();
                                }
                            }
                        });
                    }

                    else {
                        Toast.makeText(RegisterAccount.this, "Failed", Toast.LENGTH_LONG).show();
                    }
                }
            });

}

Error: Cannot resolve symbol 'RegisterAccount' for all 3 Toast-s

I tried Toast.makeText(RegisterAccount(), "Failed", Toast.LENGTH_LONG).show();, RegisterAccount() instead of RegisterAccount.this and got error: Cannot resolve method 'makeText(void, java.lang.String, int)'.

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
Ugusu
  • 13
  • 3

1 Answers1

0

You can try this:

Toast.makeText(requireActivity(), "Failed", Toast.LENGTH_LONG).show();

Or:

Toast.makeText(requireContext(), "Failed", Toast.LENGTH_LONG).show();
blaz
  • 69
  • 1
  • 5