LoginButton from Facebook SDK is null


LoginButton from Facebook SDK is null



I'm using FB SDK and LoginButton is null even if the UI shows it right.



JAVA:


loginButton = findViewById(R.id.login_button);



XML:


<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"/>



GRADLE:


compile 'com.facebook.android:facebook-login:4.34.0'





Can you check that the layout you've set in the setContentView() is the one with the button? I often make this mistake.
– Sanchita Santra
Jun 30 at 10:51





This was the problem. The button was inside of one nav_header. To access the object i used navigationView.getHeaderView(0).findViewById.
– thmmy95
Jun 30 at 12:16


navigationView.getHeaderView(0).findViewById




1 Answer
1



Try this code.. and i hope you add internet permission and other things into android manifest files..


/**
* this method used to user login with facebook.
*/
private void loginWithFacebook() {

mLoginFbButton.setReadPermissions("public_profile", "email");
mLoginFbButton.setFragment(this);
mLoginFbButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
// App code
if (Profile.getCurrentProfile() == null) {
mProfileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile profile, Profile profile2) {
registerUsingFaceBook(profile2);
}
};
} else {
registerUsingFaceBook(Profile.getCurrentProfile());
}

}

@Override
public void onCancel() {

}

@Override
public void onError(FacebookException exception) {
}
});
}



more information refer this link..
https://github.com/facebook/facebook-android-sdk





The internet permission is already set up. I've done what you suggesting, but this doesn't have any connection with my problem. If i do this, it will throw Attempt to invoke virtual method 'void com.facebook.login.widget.LoginButton.setReadPermissions(java.lang.String)' on a null object reference
– thmmy95
Jun 30 at 6:10


Attempt to invoke virtual method 'void com.facebook.login.widget.LoginButton.setReadPermissions(java.lang.String)' on a null object reference





this permission add into fb devloper option.
– Android Team
Jun 30 at 6:11





I need to say the button works as expected. (It make connection to my fb acount) Only problem is that i can't receive the object reference in java...
– thmmy95
Jun 30 at 6:13






it means not getting user profile data.
– Android Team
Jun 30 at 6:19





Could you explain what do you mean? I don't understand and i'm still trying to figure out what is the problem(in FB analytics it appears that i've connected with app but no java object refernce available)
– thmmy95
Jun 30 at 7:31






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV