title: Android Integrate Facebook NullPointerException
body: <p>Basically I am trying to integrate Facebook sharing into my Android project. I followed this <a href="http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/" rel="nofollow">Tutorial</a>. And I am currently working on the Facebook login when button onClickListener is triggered:</p>
  
  <pre><code>    ivFacebookShare.setOnClickListener(new OnClickListener(){
          public void onClick(View v){
              AndroidFacebookConnectActivity.loginToFacebook(getActivity());
          }
      });
  </code></pre>
  
  <p>And in my another class, I am executing loginToFacebook():</p>
  
  <pre><code>@SuppressWarnings("deprecation")
  public static void loginToFacebook(Activity context) {
      mPrefs = context.getPreferences(MODE_PRIVATE);
      String access_token = mPrefs.getString("access_token", null);
      long expires = mPrefs.getLong("access_expires", 0);
  
      if (access_token != null) {
          facebook.setAccessToken(access_token);
      }
  
      if (expires != 0) {
          facebook.setAccessExpires(expires);
      }
  
      if (!facebook.isSessionValid()) {
          facebook.authorize(context, new String[] { "email", "publish_stream" }, new DialogListener() {
              public void onCancel() {
              }
  
              public void onComplete(Bundle values) {
                  // Function to handle complete event
                  // Edit Preferences and update facebook acess_token
                  SharedPreferences.Editor editor = mPrefs.edit();
                  editor.putString("access_token", facebook.getAccessToken());
                  editor.putLong("access_expires", facebook.getAccessExpires());
                  editor.commit();
              }
  
              public void onError(DialogError error) {
              }
  
              public void onFacebookError(FacebookError fberror) {
              }
  
          });
      }
  }
  </code></pre>
  
  <p>However, I am getting error message as the stacktrace:</p>
  
  <pre><code>12-23 13:23:05.938: D/AndroidRuntime(29010): Shutting down VM
  12-23 13:23:05.938: W/dalvikvm(29010): threadid=1: thread exiting with uncaught exception (group=0x40c561f8)
  12-23 13:23:05.954: E/AndroidRuntime(29010): FATAL EXCEPTION: main
  12-23 13:23:05.954: E/AndroidRuntime(29010): java.lang.NullPointerException
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at nyp.edu.eneighbourhood.AndroidFacebookConnectActivity.loginToFacebook(AndroidFacebookConnectActivity.java:49)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at nyp.edu.eneighbourhood.EventDetail$3.onClick(EventDetail.java:165)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at android.view.View.performClick(View.java:3620)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at android.view.View$PerformClick.run(View.java:14292)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at android.os.Handler.handleCallback(Handler.java:605)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at android.os.Handler.dispatchMessage(Handler.java:92)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at android.os.Looper.loop(Looper.java:137)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at android.app.ActivityThread.main(ActivityThread.java:4512)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at java.lang.reflect.Method.invoke(Method.java:511)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
  12-23 13:23:05.954: E/AndroidRuntime(29010):    at dalvik.system.NativeStart.main(Native Method)
  12-23 13:23:14.618: I/Process(29010): Sending signal. PID: 29010 SIG: 9
  </code></pre>
  
  <p>Any guides? Thanks in advance.</p>