我是firebase的新手,我想第一次实现facebook auth。我可以成功获得facebook令牌但是当我调用signInWithCredential()时会抛出此异常。
引起:java.lang.NullPointerException:尝试调用虚拟 方法' com.google.android.gms.tasks.Task com.google.android.gms.common.api.GoogleApi.zzb(com.google.android.gms.common.api.internal.zzdf)' 在空对象引用上
这是我的源代码
public class LoginActivity extends AppCompatActivity {
private CallbackManager callbackManager;
private FirebaseAuth mAuth;
private String TAG = "Test";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAuth = FirebaseAuth.getInstance();
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException e) {
}
});
}
private void handleFacebookAccessToken(AccessToken token) {
AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken());
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
FirebaseUser user = mAuth.getCurrentUser();
} else {
}
}
});
}
@Override
public void onStart() {
super.onStart();
FirebaseUser currentUser = mAuth.getCurrentUser();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
感谢任何建议。
答案 0 :(得分:2)
您必须安装Google Play服务。我想你是在模拟器上测试的。尝试在真实设备上进行测试,或确保在模拟器上安装了GPS
答案 1 :(得分:0)
请检查您的FirebaseUI和Firebase / Play服务版本。他们必须根据您在这里找到的表格进行匹配: https://github.com/firebase/FirebaseUI-Android