title: Facebook ProfilePictureView : Attempt to invoke virtual method 'java.lang.String com.facebook.Profile.getId()' on a null object reference
body: <p>I'm trying to get the profile picture for a facebook profile (mine).
  Here is my android_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="fr.djey.***" &gt;
      &lt;!--android:name=".MyApplication"--&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;application
  
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:theme="@style/AppTheme" &gt;
          &lt;meta-data
              android:name="com.facebook.sdk.ApplicationId"
              android:value="@string/app_id"/&gt;
          &lt;activity
              android:name=".MainActivity"
              android:label="@string/app_name" &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.facebook.FacebookActivity"
              android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
              android:theme="@android:style/Theme.Translucent.NoTitleBar"
              android:label="@string/app_name" /&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>In gradle.build I have:</p>
  
  <pre><code>compile 'com.facebook.android:facebook-android-sdk:4.1.0'
  </code></pre>
  
  <p>I have my facebook buttons in a fragment that I call in another xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin"
      tools:context="fr.djey.***.MainFragment"&gt;
  
      &lt;com.facebook.login.widget.ProfilePictureView
          android:id="@+id/facebook_avatar"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_above="@+id/login_button"
          android:layout_centerHorizontal="true" /&gt;
  
      &lt;com.facebook.login.widget.LoginButton
          android:id="@+id/login_button"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginTop="30dp"
          android:layout_marginBottom="30dp"
          android:layout_centerInParent="true"/&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I give you my onSuccess in the fragment java:</p>
  
  <pre><code>private FacebookCallback&lt;LoginResult&gt; mCallback = new FacebookCallback&lt;LoginResult&gt;() {
          @Override
          public void onSuccess(LoginResult loginResult) {
              AccessToken accessToken = loginResult.getAccessToken();
              Profile profile = Profile.getCurrentProfile();
              ProfilePictureView FacebookAvatar = (ProfilePictureView) getView().findViewById(R.id.facebook_avatar);
              FacebookAvatar.setProfileId(profile.getId());
  
          }
  </code></pre>
  
  <p>My login with facebook works perfectly, but I try to get the profile picture and it doesn't work. My app stops when I'm logged in with facebook and I have in the logcat:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.facebook.Profile.getId()' on a null object reference
  </code></pre>
  
  <p>I see that the problem is the <strong>FacebookAvatar.setProfileId(profile.getID());</strong>
  But I don't know how to do differently.</p>
  
  <p><strong>OK It doesn't work with a fragment but works perfectly without</strong></p>
  
  <p><strong>Any idea why it doesn't work with fragment?</strong></p>