Facebook onCompleted Email java.lang.NullPointerException

喜你入骨 提交于 2019-12-01 16:33:43

Sometime it might be happen that User not set their Email Id in their Profile which are you getting in Your Facebook Login Via Android so that throws Error like Null Pointer Exception.

So You should have to check before using the Email Variable after fetching from Login that it is null or not Such as :

String email ="";
if(user.asMap().get("email") != null){
 email = user.asMap().get("email").toString();
}

You need to add "email" to the list of permissions you're requiring, otherwise the email will always be null. I don't know what version of the sdk you're using. With the last one you can write:

Collection<String> mPermissions = new ArrayList<>();
mPermissions.add("email");
LoginManager mLoginManager = LoginManager.getInstance();
CallbackManager mCallbackManager = CallbackManager.Factory.create();
FbCallback fbCallback = new FbCallback(this);
mLoginManager.registerCallback(mCallbackManager, fbCallback);
[...]
mLoginManager.logInWithReadPermissions(this, mPermissions);

By the way...remember that the user can revoke the permission or cannot grant it during the login.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!