title: NullPointerException when trying to log in to Firebase with Twitter
body: <p>I am creating an app that requires signing in with a Twitter account as an authentication method. Then it links the Twitter account to Firebase.</p>
  
  <p>I think the signing works fine but there is a problem with linking with Firebase, like some data are not retrieved properly which causes the NullPointException.</p>
  
  <p>My activity has two Twitter signing buttons with different names.</p>
  
  <p>This is my <code>onCreate()</code></p>
  
  <pre><code> protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      //Twitter.initialize(this);
      TwitterConfig config = new TwitterConfig.Builder(this)
              .logger(new DefaultLogger(Log.DEBUG))
              .twitterAuthConfig(new TwitterAuthConfig(twitterKey,twitterSecret))
              .debug(true)
              .build();
      Twitter.initialize(config);
      setContentView(R.layout.activity_sign);
  </code></pre>
  
  <p>and this is the function that sets the callback to the Twitter sign in buttons:</p>
  
  <pre><code>void setTwitterButtonsPress()
  {
     final Callback&lt;TwitterSession&gt; callback= new Callback&lt;TwitterSession&gt;() {
         @Override
         public void success(final Result&lt;TwitterSession&gt; result) {
             progressBar.setVisibility(View.VISIBLE);
             progressBar.getParent().bringChildToFront(progressBar);
             progressBarVisibility=true;
             AuthCredential credential = TwitterAuthProvider.getCredential(
                     result.data.getAuthToken().token,
                     result.data.getAuthToken().secret);
  
            mAuth.signInWithCredential(credential).addOnCompleteListener(new OnCompleteListener&lt;AuthResult&gt;() {///this is where i get the error
                 @Override
                 public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                     progressBar.setVisibility(View.GONE);
                     progressBarVisibility=false;
                 }
             }).addOnFailureListener(new OnFailureListener() {
                 @Override
                 public void onFailure(@NonNull Exception e) {
                     if(e.getMessage().equals("A network error (such as timeout, interrupted connection or unreachable host) has occurred."))
                     {
                         Toast.makeText(getBaseContext(),getString(R.string.noConnection),Toast.LENGTH_LONG).show();
                     }
                     else if(e.getMessage().contains("If you believe the country of origin was incorrectly identified"))
                     {
                         Toast.makeText(getBaseContext(),getString(R.string.notAvailableInLocation),Toast.LENGTH_LONG).show();
                     }
                     else if(e.getMessage().startsWith("An account already exists with the same email address but different sign-in credentials"))
                     {
                         Toast.makeText(getBaseContext(),getString(R.string.other_credential),Toast.LENGTH_LONG).show();
                     }
                     else
                     {
                         Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
                     }
                     CookieSyncManager.createInstance(getBaseContext());
                     CookieManager cookieManager = CookieManager.getInstance();
                     cookieManager.removeSessionCookie();
                     //Twitter.getSessionManager().clearActiveSession();
                     //Twitter.logOut();
                     TwitterCore.getInstance().getSessionManager().clearActiveSession();
                 }
             }).addOnSuccessListener(new OnSuccessListener&lt;AuthResult&gt;() {
                 @Override
                 public void onSuccess(AuthResult authResult) {
                     Intent intent=new Intent(getBaseContext(),add_password_activity.class);
                     intent.putExtra("checked",true);
                     startActivity(intent);
                     finish();
                 }
             });
         }
  
         @Override
         public void failure(TwitterException e) {
              Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
         }
     };
     TwitterSignUp.setCallback(callback);
     twitterSignIn.setCallback(callback);
  }
  </code></pre>
  
  <p>and this is the <code>onActivityResult()</code> function, only the last two lines are important:</p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      callbackManagerFacebook.onActivityResult(requestCode, resultCode, data);
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == googleSign)
      {
          Task&lt;GoogleSignInAccount&gt; task = GoogleSignIn.getSignedInAccountFromIntent(data);
          try {
  
              GoogleSignInAccount account = task.getResult(ApiException.class);
              AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(), null);
              progressBar.setVisibility(View.VISIBLE);
              progressBar.getParent().bringChildToFront(progressBar);
              progressBarVisibility=true;
              mAuth.signInWithCredential(credential)
                      .addOnCompleteListener(this, new OnCompleteListener&lt;AuthResult&gt;() {
                          @Override
                          public void onComplete(@NonNull Task&lt;AuthResult&gt; task) {
                              progressBar.setVisibility(View.GONE);
                              progressBarVisibility=false;
                          }
                      }).addOnSuccessListener(new OnSuccessListener&lt;AuthResult&gt;() {
                  @Override
                  public void onSuccess(AuthResult authResult) {
                      Intent intent=new Intent(getBaseContext(),add_password_activity.class);
                      intent.putExtra("checked",true);
                      startActivity(intent);
                      finish();
                  }
              }).addOnFailureListener(new OnFailureListener() {
                  @Override
                  public void onFailure(@NonNull Exception e) {
                      if(e.getMessage().equals("A network error (such as timeout, interrupted connection or unreachable host) has occurred."))
                      {
                          Toast.makeText(getBaseContext(),getString(R.string.noConnection),Toast.LENGTH_LONG).show();
                      }
                      else if(e.getMessage().contains("If you believe the country of origin was incorrectly identified"))
                      {
                          Toast.makeText(getBaseContext(),getString(R.string.notAvailableInLocation),Toast.LENGTH_LONG).show();
                      }
                      else if(e.getMessage().startsWith("An account already exists with the same email address but different sign-in credentials"))
                      {
                          Toast.makeText(getBaseContext(),getString(R.string.other_credential),Toast.LENGTH_LONG).show();
                      }
                      else
                      {
                          Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
                      }
                      googleSignInClient.signOut();
                  }
              });
          } catch (ApiException e) {
              if(e.getMessage().contains("12500:"))
              {
                  Intent intent=new Intent(getBaseContext(),update_play_services.class);
                  startActivity(intent);
              }
              else if(e.getMessage().contains("7:"))
              {
                  Toast.makeText(getBaseContext(),getString(R.string.noConnection),Toast.LENGTH_LONG).show();
              }
              else Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
          }
      }
  
      if(data!=null)TwitterSignUp.onActivityResult(requestCode, resultCode, data);
      if(data!=null)twitterSignIn.onActivityResult(requestCode, resultCode, data);
  }
  </code></pre>
  
  <p>and I put the meta data for the fabric io in the manifest file like the following:</p>
  
  <pre><code>&lt;meta-data
          android:name="io.fabric.ApiKey"
          android:value="***************************" /&gt;
  </code></pre>
  
  <p>this is the error message in datails:</p>
  
  <pre><code>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=140, result=-1, data=Intent { (has extras) }} to activity {arb.passwordmanager/arb.passwordmanager.Sign}: java.lang.NullPointerException
                                                                         at android.app.ActivityThread.deliverResults(ActivityThread.java:3433)
                                                                         at android.app.ActivityThread.handleSendResult(ActivityThread.java:3476)
                                                                         at android.app.ActivityThread.access$1200(ActivityThread.java:157)
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                         at android.os.Looper.loop(Looper.java:176)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5317)
                                                                         at java.lang.reflect.Method.invokeNative(Native Method)
                                                                         at java.lang.reflect.Method.invoke(Method.java:511)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
                                                                         at dalvik.system.NativeStart.main(Native Method)
                                                                      Caused by: java.lang.NullPointerException
                                                                         at com.google.android.gms.internal.zzdza.zzb(Unknown Source)
                                                                         at com.google.android.gms.internal.zzdzh.zza(Unknown Source)
                                                                         at com.google.firebase.auth.FirebaseAuth.signInWithCredential(Unknown Source)
                                                                         at arb.passwordmanager.Sign$10.success(Sign.java:616)
                                                                         at com.twitter.sdk.android.core.identity.TwitterAuthClient$CallbackWrapper.success(TwitterAuthClient.java:238)
                                                                         at com.twitter.sdk.android.core.identity.AuthHandler.handleOnActivityResult(AuthHandler.java:92)
                                                                         at com.twitter.sdk.android.core.identity.TwitterAuthClient.onActivityResult(TwitterAuthClient.java:171)
                                                                         at com.twitter.sdk.android.core.identity.TwitterLoginButton.onActivityResult(TwitterLoginButton.java:130)
                                                                         at arb.passwordmanager.Sign.onActivityResult(Sign.java:774)
                                                                         at android.app.Activity.dispatchActivityResult(Activity.java:5515)
                                                                         at android.app.ActivityThread.deliverResults(ActivityThread.java:3429)
                                                                         at android.app.ActivityThread.handleSendResult(ActivityThread.java:3476) 
                                                                         at android.app.ActivityThread.access$1200(ActivityThread.java:157) 
                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337) 
                                                                         at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                         at android.os.Looper.loop(Looper.java:176) 
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5317) 
                                                                         at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                         at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
                                                                         at dalvik.system.NativeStart.main(Native Method) 
  </code></pre>