1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Android]

Discussão em 'Mobile' iniciado por Stack, Janeiro 15, 2021.

  1. Stack

    Stack Membro Participativo

    Não estou conseguindo achar uma solução para o meu problema. O APP fecha ao clicar no button "Cadastrar"

    public class CadastroActivity extends AppCompatActivity {

    private EditText campoNome, campoEmail, campoSenha;
    private Button buttonCadastrar;
    private FirebaseAuth autenticacao;
    private Usuario usuario;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cadastro);


    campoEmail = findViewById(R.id.editEmail);
    campoNome = findViewById(R.id.editNome);
    campoSenha = findViewById(R.id.editSenha);
    buttonCadastrar = findViewById(R.id.buttonCadastrar);

    buttonCadastrar.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {

    String textoNome = campoNome.getText().toString();
    String textoEmail = campoEmail.getText().toString();
    String textoSenha = campoSenha.getText().toString();

    //Validar se os campos foram preenchidos
    if (!textoNome.isEmpty()){
    if (!textoEmail.isEmpty()){
    if (!textoSenha.isEmpty()){

    usuario = new Usuario();
    usuario.setNome(textoNome);
    usuario.setEmail(textoEmail);
    usuario.setSenha(textoSenha);
    cadastrarUsuario();
    }else {
    Toast.makeText(CadastroActivity.this,
    "Preencha a senha!",
    Toast.LENGTH_SHORT).show();
    }
    }else {
    Toast.makeText(CadastroActivity.this,
    "Preencha o Email!",
    Toast.LENGTH_SHORT).show();
    }
    }else {
    Toast.makeText(CadastroActivity.this,
    "Preencha o nome!",
    Toast.LENGTH_SHORT).show();
    }

    }
    });

    }

    public void cadastrarUsuario(){

    autenticacao = ConfiguracaoFirabase.getFirebaseAutenticacao();
    autenticacao.createUserWithEmailAndPassword(
    usuario.getEmail(), usuario.getSenha()
    ).addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
    @Override
    public void onComplete(@NonNull Task<AuthResult> task) {
    if (task.isSuccessful()){
    Toast.makeText(CadastroActivity.this,
    "Sucesso ao cadastrar usuário!",
    Toast.LENGTH_SHORT).show();
    }else {

    String excecao = "";
    try{
    throw task.getException();
    }catch (FirebaseAuthWeakPasswordException e){
    excecao = "Digite uma senha mais forte!";
    }catch (FirebaseAuthInvalidCredentialsException e){
    excecao = "Por favor, Digite um e-mail válido!";
    }catch (FirebaseAuthUserCollisionException e){
    excecao = "Esta conta já foi cadastrada!";
    }catch (Exception e){
    excecao = "Erro ao cadastrar usuário: " + e.getMessage();
    e.printStackTrace();
    }

    Toast.makeText(CadastroActivity.this,
    excecao,
    Toast.LENGTH_SHORT).show();
    }
    }
    });

    }


    }

    Continue reading...

Compartilhe esta Página