Error "Unfortunately Myapp has stopped" when clicking the application button

Asked

Viewed 340 times

0

I’m running my app on Genymotion, developing on Android Studio.

Every time I run my application I click on the button to register, but when I click I come across the following message "Unfortunately Myapp has stopped", where after the application is finished.

Note: I am using Firebase to register the data

Code of my Activity

    package com.example.matheus.MyApp;

    import android.content.Intent;
    import android.support.annotation.NonNull;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    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.auth.FirebaseUser;

public class CadastroActivity extends AppCompatActivity  {

    private Button mCadastro;
    private EditText mEmail, mSenha;
    private FirebaseAuth mAuth;
    private FirebaseAuth.AuthStateListener firebaseAuthStateListener;

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

        mAuth = FirebaseAuth.getInstance();
        firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                if (user !=null){
                    Intent intent = new Intent(CadastroActivity.this, MainActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }
        };

        mCadastro = (Button) findViewById(R.id.cadastrar);

        mEmail = (EditText) findViewById(R.id.email);
        mSenha = (EditText) findViewById(R.id.senha);

        mCadastro.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final String email = mEmail.getText().toString();
                final String senha = mSenha.getText().toString();


      //linha 56 AQUI          mAuth.createUserWithEmailAndPassword(email, senha).addOnCompleteListener(CadastroActivity.this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (!task.isSuccessful()){
                            Toast.makeText(CadastroActivity.this, "Cadastrado com sucesso! Efetue o login", Toast.LENGTH_SHORT).show();

                        }
                    }
                });
            }
        });

    }


    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(firebaseAuthStateListener);
    }

    @Override
    protected void onStop() {
        super.onStop();
        mAuth.removeAuthStateListener(firebaseAuthStateListener);
    }
}

Code detailing where the error is:

02-17 13:27:45.439 1961-1961/com.example.Matheus.Myapp E/Androidruntime: FATAL EXCEPTION: main Process: com.example.Matheus.Myapp, PID: 1961 java.lang.Nullpointerexception at com.google.android.gms.Internal.zzdtp.zzb(Unknown Source) at com.google.android.gms.Internal.zzdtw.zza(Unknown Source) at com.google.firebase.auth.Firebaseuth.createUserWithEmailAndPassword(Unknown Source) at com.example.Matheus.MyApp.Cadastroactivity$2.onClick(Cadastroactivity.java:56) at android.view.View.performClick(View.java:4438) at android.view.View$Performclick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.Activitythread.main(Activitythread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:785) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:601) at Dalvik.system.Nativestart.main(Native Method)

  • mAuth = Firebaseuth.getInstance(); what is the return of this line ? is returned at some instance or is returning null ?

  • For this Activity returns null (so I understand).. Will save the data registered in firebase and other Activity will check the authentication..

  • 1

    Could you tell which android sdk settings of the project, and which android version vc is testing?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.