title: Null pointer exception while integrating Facebook login with android app
body: <p>I have got null pointer exception while integrating facebook login with my android app. I followed <a href="https://developers.facebook.com/docs/android/scrumptious/authenticate" rel="nofollow">this</a> tutorial. I have attached written codes also.
  FacebookLogin.java</p>
  
  <pre><code> public class FacebookLogin extends FragmentActivity{
      private static final int SPLASH = 0;
      private static final int SELECTION = 1;
      private static final int FRAGMENT_COUNT = SELECTION +1;
      private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
      private boolean isResumed = false;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.main);
          uiHelper = new UiLifecycleHelper(this, callback);
          uiHelper.onCreate(savedInstanceState);
  
          FragmentManager fm = getSupportFragmentManager();
          fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
         // fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
          FragmentTransaction transaction = fm.beginTransaction();
          for(int i = 0; i &lt; fragments.length; i++) {
              transaction.hide(fragments[i]);
          }
          transaction.commit();
      }
      private void showFragment(int fragmentIndex, boolean addToBackStack) {
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction transaction = fm.beginTransaction();
          for (int i = 0; i &lt; fragments.length; i++) {
              if (i == fragmentIndex) {
                  transaction.show(fragments[i]);
              } else {
                  transaction.hide(fragments[i]);
              }
          }
          if (addToBackStack) {
              transaction.addToBackStack(null);
          }
          transaction.commit();
      }
  
      @Override
      public void onResume() {
          super.onResume();
          isResumed = true;
          uiHelper.onResume();
          isResumed = true;
      }
  
      @Override
      public void onPause() {
          super.onPause();
          isResumed = false;
          uiHelper.onPause();
          isResumed = false;
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          uiHelper.onActivityResult(requestCode, resultCode, data);
      }
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          uiHelper.onDestroy();
      }
  
      @Override
      protected void onSaveInstanceState(Bundle outState) {
          super.onSaveInstanceState(outState);
          uiHelper.onSaveInstanceState(outState);
      }
  
      private void onSessionStateChange(Session session, SessionState state, Exception exception) {
          // Only make changes if the activity is visible
          if (isResumed) {
              FragmentManager manager = getSupportFragmentManager();
              // Get the number of entries in the back stack
              int backStackSize = manager.getBackStackEntryCount();
              // Clear the back stack
              for (int i = 0; i &lt; backStackSize; i++) {
                  manager.popBackStack();
              }
              if (state.isOpened()) {
                  // If the session state is open:
                  // Show the authenticated fragment
                  showFragment(SELECTION, false);
              } else if (state.isClosed()) {
                  // If the session state is closed:
                  // Show the login fragment
                  showFragment(SPLASH, false);
              }       }   }   
      @Override
      protected void onResumeFragments() {
          super.onResumeFragments();
          Session session = Session.getActiveSession();
  
          if (session != null &amp;&amp; session.isOpened()) {
              // if the session is already open,
              // try to show the selection fragment
              showFragment(SELECTION, false);
          } else {
              // otherwise present the splash screen
              // and ask the person to login.
              showFragment(SPLASH, false);
          }   }
      private UiLifecycleHelper uiHelper;
      private Session.StatusCallback callback = 
          new Session.StatusCallback() {
          @Override
          public void call(Session session, 
                  SessionState state, Exception exception) {
              onSessionStateChange(session, state, exception);
          }   };
  }
  </code></pre>
  
  <p>SplashFragment.java</p>
  
  <pre><code>public class SplashFragment extends Fragment {
  private Button skipLoginButton;
  private SkipLoginCallback skipLoginCallback;
  
  public interface SkipLoginCallback {
      void onSkipLoginPressed();
  }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.splash, container, false);
  
      skipLoginButton = (Button) view.findViewById(R.id.login_button);
      skipLoginButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if (skipLoginCallback != null) {
                  skipLoginCallback.onSkipLoginPressed();
              }            }        });
      return view;
  }
  
  public void setSkipLoginCallback(SkipLoginCallback callback) {
      skipLoginCallback = callback;
  }}
  </code></pre>
  
  <p>main.xml</p>
  
  <pre><code>    &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
     &lt;!--  &lt;fragment android:name="com.GenioCode.replay.SelectionFragment"
            android:id="@+id/selectionFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" /&gt;--&gt;
      &lt;fragment android:name="com.GenioCode.replay.SplashFragment"
            android:id="@+id/splashFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent" /&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>LogCat</p>
  
  <pre><code>    12-22 01:12:05.432: E/AndroidRuntime(1555): FATAL EXCEPTION: main
  12-22 01:12:05.432: E/AndroidRuntime(1555): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.GenioCode.replay/com.GenioCode.replay.FacebookLogin}: java.lang.NullPointerException
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.os.Handler.dispatchMessage(Handler.java:99)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.os.Looper.loop(Looper.java:137)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.ActivityThread.main(ActivityThread.java:5103)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at java.lang.reflect.Method.invokeNative(Native Method)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at java.lang.reflect.Method.invoke(Method.java:525)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at dalvik.system.NativeStart.main(Native Method)
  12-22 01:12:05.432: E/AndroidRuntime(1555): Caused by: java.lang.NullPointerException
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:656)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:556)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.Activity.performStart(Activity.java:5143)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
  12-22 01:12:05.432: E/AndroidRuntime(1555):     ... 11 more
  </code></pre>
  
  <p>Please help me to solve this exception.</p>