title: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()'
body: <pre><code>Process: com.example.vicevirus.myapplication, PID: 13471  
      java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference
                at com.example.vicevirus.myapplication.RegisterActivity$1.onComplete(RegisterActivity.java:48)
                at com.google.android.gms.tasks.zzc$1.run(Unknown Source)
                at android.os.Handler.handleCallback(Handler.java:751)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:154)
                at android.app.ActivityThread.main(ActivityThread.java:6119)
                at java.lang.reflect.Method.invoke(Native Method)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
  </code></pre>
  
  <p>This is on android monitor. How do I solve this?</p>
  
  <pre><code>package com.example.vicevirus.myapplication;
  
  import android.app.ProgressDialog;
           import android.support.annotation.NonNull;
           import android.support.v7.app.AppCompatActivity;
           import android.os.Bundle;
           import android.view.View;
           import android.widget.EditText;
           import android.widget.Toast;
           import com.google.android.gms.tasks.OnCompleteListener;
           import com.google.android.gms.tasks.OnSuccessListener;
           import com.google.android.gms.tasks.Task;
           import com.google.firebase.auth.AuthResult;
           import com.google.firebase.auth.FirebaseAuth;
           import com.google.firebase.database.DatabaseReference;
           import com.google.firebase.database.FirebaseDatabase;
  
  public class RegisterActivity extends AppCompatActivity {
      private EditText email,name,password;
      DatabaseReference databaseReference;
      FirebaseAuth mAuth;
      private DatabaseReference userIdRef;
      ProgressDialog registerDialog;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_register);
          email=(EditText)findViewById(R.id.email);
          name=(EditText)findViewById(R.id.name);
          password=(EditText)findViewById(R.id.password);
          databaseReference= FirebaseDatabase.getInstance().getReference().child("chat_users");
          mAuth=FirebaseAuth.getInstance();
          registerDialog=new ProgressDialog(this);
          registerDialog.setMessage("Registering..");
      }
      public void submit(View view) {
          registerDialog.show();
          mAuth.createUserWithEmailAndPassword(email.getText().toString(),password.getText().toString()).addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                  if(task.isComplete())
                  {
                      registerDialog.dismiss();
                      Toast.makeText(getApplicationContext(),"Registered successfully",Toast.LENGTH_SHORT).show();
                      userIdRef=databaseReference.child(mAuth.getCurrentUser().getUid());
                      userIdRef.child("name").setValue(name.getText().toString());
                      finish();
                  }
                  registerDialog.dismiss();
              }
          });
      }
  }
  </code></pre>