Android Custom Facebook Login Integration
<p>I found an example for fb login.Its getting crashed
This is the error:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.facebook.Profile.getFirstName()' on a null object reference</p>

<p>I want to do just click on button  facebook will go to next page and need to show profile pic and emailid on new Activity..Any suggestion or any link will be helpful..Please guys</p>

<p><a href="https://inducesmile.com/android/android-facebook-sdk-login-integration-and-display-facebook-user-profile/" rel="nofollow noreferrer">https://inducesmile.com/android/android-facebook-sdk-login-integration-and-display-facebook-user-profile/</a></p>

<pre><code>public class MainActivity extends AppCompatActivity {
private CallbackManager callbackManager;
ImageView fb_img;
public static final String PROFILE_USER_ID = "USER_ID";
public static final String PROFILE_FIRST_NAME = "PROFILE_FIRST_NAME";
public static final String PROFILE_LAST_NAME = "PROFILE_LAST_NAME";
public static final String PROFILE_IMAGE_URL = "PROFILE_IMAGE_URL";

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_main);
    callbackManager = CallbackManager.Factory.create();
    LoginButton mLoginButton = (LoginButton)findViewById(R.id.mLoginButton);
   // fb_img = (ImageView) findViewById(R.id.fb_img);


        // Callback registration
    mLoginButton.registerCallback(callbackManager, new FacebookCallback&lt;LoginResult&gt;() {
        @Override
        public void onSuccess(LoginResult loginResult) {

           String userLoginId = loginResult.getAccessToken().getUserId();
            Intent facebookIntent = new Intent(getApplicationContext(), SecondActivity.class);
            Profile mProfile = Profile.getCurrentProfile();
            String firstName = mProfile.getFirstName();
           String lastName = mProfile.getLastName();
           String userId = mProfile.getId().toString();
            String profileImageUrl = mProfile.getProfilePictureUri(96, 96).toString();
          facebookIntent.putExtra(PROFILE_USER_ID, userId);
            facebookIntent.putExtra(PROFILE_FIRST_NAME, firstName);
           facebookIntent.putExtra(PROFILE_LAST_NAME, lastName);
            facebookIntent.putExtra(PROFILE_IMAGE_URL, profileImageUrl);
            startActivity(facebookIntent);
        }


        @Override
        public void onCancel() {
            //  Toast.makeText(SignIn.this, "Login Cancel", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            // Toast.makeText(SignIn.this, "Exceptional Error", Toast.LENGTH_LONG).show();
        }
    });


}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}



}
</code></pre>

<p>Here is my Second Activity:</p>

<pre><code>public class SecondActivity extends  AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            FacebookSdk.sdkInitialize(getApplicationContext());
            setContentView(R.layout.activity_second);


            ImageView profileView = (ImageView) findViewById(R.id.profileView);
            TextView profileName = (TextView) findViewById(R.id.profileName);
            TextView profileUserId = (TextView) findViewById(R.id.profileUserId);
            String profileUserID = returnValueFromBundles(MainActivity.PROFILE_USER_ID);
           // String profileFirstName = returnValueFromBundles(MainActivity.PROFILE_FIRST_NAME);
           // String profileLastName = returnValueFromBundles(MainActivity.PROFILE_LAST_NAME);
            String profileImageLink = returnValueFromBundles(MainActivity.PROFILE_IMAGE_URL);
           // profileName.setText(profileFirstName + " " + profileLastName);
            profileUserId.setText("User ID : " + profileUserID);
            Picasso.with(SecondActivity.this).load(profileImageLink).into(profileView);
    }

    private String returnValueFromBundles(String key) {
            Bundle inBundle = getIntent().getExtras();
            String returnedValue = inBundle.get(key).toString();
            return returnedValue;

    }
</code></pre>

<p>}</p>