title: Android Facebook SDK with fragment
body: <p>I'm trying to follow the facebook tutorial here <a href="https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/" rel="nofollow">https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/</a> but i'm getting an error with onActivityResult any ideas? The only difference between mine and theirs is mine is a fragment instead.</p>
  
  <pre><code>    package com.projectcaruso.naturalfamilyplaning;
  
      import com.facebook.*;
      import com.facebook.model.*;
      import com.projectcaruso.naturalfamilyplanning.R;
  
      import android.os.Bundle;
      import android.support.v4.app.Fragment;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.TextView;
      import android.widget.Toast;
      import android.content.Context;
      import android.content.Intent;
  
      public class facebooklogin  extends Fragment{
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState); 
          }       
  
           @Override
           public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
               View view = inflater.inflate(R.layout.fragment_login, container, false);
  
              // start Facebook Login
              Session.openActiveSession(getActivity(), this, true, new Session.StatusCallback() {
  
                // callback when session changes state
                @Override
                public void call(Session session, SessionState state, Exception exception) {
                  if (session.isOpened()) {
  
                    // make request to the /me API
                    Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
  
                      // callback after Graph API response with user object
                      @Override
                      public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            Context context = getActivity();
                            Toast.makeText(context, "Hello " + user.getName() + "!", Toast.LENGTH_LONG).show();
                        }
                      }
                    });
                  }
                }
              });
  
              return view;
            }
  
            @Override
            public void onActivityResult(int requestCode, int resultCode, Intent data) {
                super.onActivityResult(requestCode, resultCode, data);
                Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
            }
  
      }
  </code></pre>
  
  <p>EDIT:
  I changed this to getActivity() but now i get this</p>
  
  <pre><code>05-14 17:10:23.904: E/AndroidRuntime(791): FATAL EXCEPTION: main
  05-14 17:10:23.904: E/AndroidRuntime(791): java.lang.NullPointerException: Argument 'applicationId' cannot be null
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.facebook.internal.Validate.notNull(Validate.java:29)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.facebook.Session.&lt;init&gt;(Session.java:224)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.facebook.Session.&lt;init&gt;(Session.java:213)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.facebook.Session$Builder.build(Session.java:1454)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.facebook.Session.openActiveSession(Session.java:863)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.facebook.Session.openActiveSession(Session.java:828)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.projectcaruso.naturalfamilyplaning.facebookFragment.onCreateView(facebookFragment.java:29)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at     android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.os.Handler.handleCallback(Handler.java:725)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.os.Handler.dispatchMessage(Handler.java:92)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.os.Looper.loop(Looper.java:137)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at android.app.ActivityThread.main(ActivityThread.java:5041)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at java.lang.reflect.Method.invokeNative(Native Method)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at java.lang.reflect.Method.invoke(Method.java:511)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  05-14 17:10:23.904: E/AndroidRuntime(791):  at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>FYI this is in my manifest and so is the app_id in my string file.</p>
  
  <pre><code>meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"
  </code></pre>
  
  <p>manifest:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
      &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.projectcaruso.naturalfamilyplanning"
          android:versionCode="1"
          android:versionName="1.0" &gt;
  
          &lt;uses-sdk
              android:minSdkVersion="14"
              android:targetSdkVersion="17" /&gt;
  
          &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
          &lt;meta-data 
              android:name="com.facebook.sdk.ApplicationId" 
              android:value="@string/app_id"/&gt;
  
          &lt;application
              android:allowBackup="true"
              android:icon="@drawable/ic_launcher"
              android:label="@string/app_name"
              android:theme="@style/AppTheme" &gt;
              &lt;activity
                  android:name="com.projectcaruso.naturalfamilyplaning.FragmentChange"
                  android:configChanges="orientation|screenSize|screenLayout"
                  android:theme="@style/Theme.Sherlock.Light.DarkActionBar"
                  android:uiOptions="splitActionBarWhenNarrow" &gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                      &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/activity&gt;
              &lt;activity android:name="com.projectcaruso.naturalfamilyplaning.UserSettingActivity" &gt;
              &lt;/activity&gt;
              &lt;activity
                  android:name="com.projectcaruso.naturalfamilyplaning.HistoryFragment"
                  android:label="@string/title_activity_history_fragment" &gt;
              &lt;/activity&gt;
          &lt;/application&gt;
  
      &lt;/manifest&gt;
  </code></pre>