有时(不是很频繁)我的 android 应用程序在第一次使用 Facebook 登录(Facebook SDK 版本 3.5)登录到 Facebook 后崩溃。
我遇到了异常:
java.lang.RuntimeException: Unable to resume activity {my.app.package/com.facebook.LoginActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {my.app.package/com.facebook.LoginActivity}: java.lang.NullPointerException
有 2 个不同的根异常:
有时与:
java.lang.NullPointerException at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:135)
而有时:
Caused by: java.lang.NullPointerException at com.facebook.AuthorizationClient.logAuthorizationMethodComplete(AuthorizationClient.java:519)
在大多数情况下,我的应用程序运行良好。
任何想法可能导致此问题?
编辑:
我在清单中的 facebook sdk conf:
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/applicationId" />
活动代码:
public class MainActivity extends FragmentActivity {
....
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initSession(savedInstanceState);
...
}
private void initSession(Bundle savedInstanceState) {
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(this, null, statusCallback, savedInstanceState);
}
if (session == null) {
session = new Session(this);
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
}
@Override
public void onStart() {
super.onStart();
Session session = Session.getActiveSession();
if (session != null) {
session.addCallback(statusCallback);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session session = Session.getActiveSession();
if (session != null) {
session.onActivityResult(this, requestCode, resultCode, data);
}
}
@Override
public void onStop() {
super.onStop();
Session session = Session.getActiveSession();
if (session != null) {
session.removeCallback(statusCallback);
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
...
}
我在以前版本的 Facebook SDK 中也遇到了这个错误。我有最新的 Fb 安卓客户端。有什么帮助吗?