title: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()' on a null object reference
body: <blockquote>
    <p>Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()'
    on a null object reference
    com.pravin.yashlalit.msbtestudymaterial.Authentications.SigninActivity.FirebaseGoogleAuth</p>
  </blockquote>
  
  <p>I have to publish a new update of my application introducing a Google Sign In for the users in that updated version. Every day around 6-7 crashes are registered for this specific issue. I am not able to find any solution to this.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class SigninActivity extends AppCompatActivity {
  
      SignInButton signInButton;
      GoogleSignInClient mGoogleSignInClient;
      String TAG="SigninActivity";
      FirebaseAuth mAuth;
      int RC_SIGN_IN =1;
      String personName,personGivenName,personEmail,personId;
      Uri personPhoto;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_signin);
  
          initializations();
  
      }
  
      private void initializations() {
          signInButton = findViewById(R.id.google_btn);
          mAuth = FirebaseAuth.getInstance();
  
          GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                  .requestIdToken(getString(R.string.default_web_client_id))
                  .requestEmail()
                  .build();
  
          mGoogleSignInClient = GoogleSignIn.getClient(this,gso);
  
          signInButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  signIn();
              }
          });
      }
  
      private void signIn() {
          Intent signInIntent = mGoogleSignInClient.getSignInIntent();
          startActivityForResult(signInIntent,RC_SIGN_IN);
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
  
          if (requestCode==RC_SIGN_IN)
          {
              Task&lt;GoogleSignInAccount&gt; task = GoogleSignIn.getSignedInAccountFromIntent(data);
              handleSignInResult(task);
          }
      }
  
      private void handleSignInResult(Task&lt;GoogleSignInAccount&gt; task) {
          try{
              GoogleSignInAccount acc = task.getResult(ApiException.class);
              Toast.makeText(getApplicationContext(),"Signing Success",Toast.LENGTH_SHORT).show();
              FirebaseGoogleAuth(acc);
          }catch(ApiException e)
          {
              Toast.makeText(getApplicationContext(),"Signing FAiled",Toast.LENGTH_SHORT).show();
              FirebaseGoogleAuth(null);
          }
      }
  
      private void FirebaseGoogleAuth(GoogleSignInAccount acc) {
          AuthCredential authCredential = GoogleAuthProvider.getCredential(acc.getIdToken(),null);
          mAuth.signInWithCredential(authCredential).addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
              @Override
              public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                    if (task.isSuccessful())
                    {
                        Toast.makeText(getApplicationContext(),"Firebase Success",Toast.LENGTH_SHORT).show();
                        FirebaseUser user = mAuth.getCurrentUser();
                        updateUI(user);
                    }
                    else
                    {
                        Toast.makeText(getApplicationContext(),"Firebase Failed",Toast.LENGTH_SHORT).show();
                        updateUI(null);
                    }
              }
          });
      }
  
      private void updateUI(FirebaseUser user) {
          GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(getApplicationContext());
          if (account != null)
          {
               personName = account.getDisplayName();
               personGivenName = account.getGivenName();
               personEmail = account.getEmail();
               personId = account.getId();
               personPhoto = account.getPhotoUrl();
  
            /*  Toast.makeText(getApplicationContext(),"User Information:" +
                        "\nName: "+personName+
                      "\nGiven: "+personGivenName+
                      "\nEmail: "+personEmail+
                      "\nId: "+personId+
                      "\nPhoto: "+personPhoto.toString(),
                      Toast.LENGTH_SHORT).show();*/
  
              sendUserToSetupActivity(personName,personEmail,personPhoto);
  
          }
  
  
      }
  
      private void sendUserToSetupActivity(String personName, String personEmail, Uri personPhoto) {
          startActivity(new Intent(getApplicationContext(),SetupActivity.class)
                          .putExtra("Name",personName)
                          .putExtra("Email",personEmail)
                          .putExtra("Photo",personPhoto.toString())
                       );
          this.finish();
  
      }
  
      @Override
      protected void onStart() {
          super.onStart();
  
          FirebaseUser currentUser = mAuth.getCurrentUser();
  
          if (currentUser != null) {
              sendUserToMainActivity();
          }
      }
      private void sendUserToMainActivity() {
          startActivity(new Intent(getApplicationContext(), MainActivity.class));
          this.finish();
      }
  }
  </code></pre>
  
  <p>This is what i see in my crashlytics</p>
  
  <p><a href="https://i.stack.imgur.com/82CpQ.png" rel="nofollow noreferrer">crashlytics data</a></p>
  
  <p><a href="https://i.stack.imgur.com/Q6iT1.png" rel="nofollow noreferrer">crashlytics stack traces</a></p>