title: How can i fix null pointer exception in Firebase Authentication?
body: <p>I need help with this one. Everytime i run the app, its just crashed everytime opened on login activity. Please help, im stucked with this.
  I've follow much tutorial, and i think the code was same but still got null pointer exception. I have no idea how to fix this null pointer.</p>
  
  <p>Logcat :</p>
  
  <pre><code>java.lang.NullPointerException: Attempt to invoke interface method 'void com.google.firebase.auth.FirebaseAuth$AuthStateListener.onAuthStateChanged(com.google.firebase.auth.FirebaseAuth)' on a null object reference
      at com.google.firebase.auth.zzi.run(Unknown Source:2)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at com.google.android.gms.internal.firebase_auth.zzj.dispatchMessage(Unknown Source:6)
      at android.os.Looper.loop(Looper.java:193)
      at android.app.ActivityThread.main(ActivityThread.java:6718)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:495)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>
  
  <p>My code on Login Activity :</p>
  
  <pre><code>public class Login extends AppCompatActivity {
  
      private FirebaseAuth mAuth;
      FirebaseAuth.AuthStateListener mAuthListner;
  
      Button btnlogin;
      TextView btndaftar;
      MaterialEditText mEmail, pass;
  
      @Override
      protected void onStart() {
          super.onStart();
          FirebaseUser currentUser = mAuth.getCurrentUser();
          updateUI(currentUser);
      }
  
      private void updateUI(FirebaseUser currentUser) {
      }
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          mAuth = FirebaseAuth.getInstance();
  
          mAuth.addAuthStateListener(mAuthListner);
  
          mAuthListner = new FirebaseAuth.AuthStateListener() {
              @Override
              public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                  FirebaseUser user = firebaseAuth.getCurrentUser();
                  if (user != null) {
                      Intent intent = new Intent(Login.this, NavigationMenu.class);
                      startActivity(intent);
                      finish();
                  }
              }
          };
  
          btnlogin=findViewById(R.id.btnLogin);
          mEmail=findViewById(R.id.edt_email);
          pass=findViewById(R.id.edt_pasword);
          btndaftar=findViewById(R.id.btnDaftar);
  
          btndaftar.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent daftar = new Intent(Login.this, Daftar.class);
                  startActivity(daftar);
              }
          });
  
  
  
          btnlogin.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  String email = mEmail.getText().toString();
                  String password = pass.getText().toString();
  
                  mAuth.signInWithEmailAndPassword(email, password)
                          .addOnCompleteListener(Login.this, new OnCompleteListener&lt;AuthResult&gt;() {
                              @Override
                              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                                  if (task.isSuccessful()) {
                                      // Sign in success, update UI with the signed-in user's information
                                      Intent intent = new Intent(Login.this, NavigationMenu.class);
                                      startActivity(intent);
                                      finish();
                                      FirebaseUser currentUser = mAuth.getCurrentUser();
                                      updateUI(currentUser);
                                  } else {
                                      // If sign in fails, display a message to the user.
                                      Toast.makeText(Login.this, "Login gagal !",
                                              Toast.LENGTH_SHORT).show();
                                      updateUI(null);
                                  }
                              }
                          });
             }
          });
      }
  }
  </code></pre>
  
  <p>Right after app opened, its just crashed. any idea why this happened?</p>