7

有时(不是很频繁)我的 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 安卓客户端。有什么帮助吗?

4

3 回答 3

4

Facebook 昨天刚刚发布了他们的 Android SDK v3.5.1 来解决您的问题。他们的变更日志没有提供太多关于哪里出了问题的信息,但是人们一直在报告这个错误,他们确实说它将在以后的版本中修复(来源)。但无论如何,看看 v3.5 和 v3.5.1 之间的差异,它们似乎在第 135 行和第 519 行有固定的代码。查看更改日志的完整列表。在他们发布第一个补丁之前,永远不要从 Facebook 升级到重要版本,这可能是个好主意。

于 2013-09-27T03:07:30.220 回答
0

我今天遇到了同样的问题。Facebook SDK 3.5 似乎与 Facebook 2.1 等旧版 Facebook 客户端不兼容。我将 Facebook 客户端更新到最新版本,然后它就可以工作了。

 09-13 17:50:43.592   11372.11372                 Bundle  W  Key com.facebook.platform.protocol.PROTOCOL_VERSION expected String but value was a java.lang.Integer.  The default
                                                              value <null> was returned.
 09-13 17:50:43.602   11372.11372                 Bundle  W  Attempt to cast generated internal exception:
 09-13 17:50:43.602   11372.11372                 Bundle  W  java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.os.Bundle.getString(Bundle.java:1085)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.content.Intent.getStringExtra(Intent.java:4826)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.facebook.AuthorizationClient$KatanaLoginDialogAuthHandler.tryAuthorize(AuthorizationClient.java:821)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:272)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.facebook.AuthorizationClient.tryNextHandler(AuthorizationClient.java:238)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.facebook.AuthorizationClient.authorize(AuthorizationClient.java:161)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:142)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.facebook.LoginActivity.onResume(LoginActivity.java:117)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1282)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.Activity.performResume(Activity.java:5287)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3211)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3266)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2579)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.ActivityThread.access$600(ActivityThread.java:162)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1413)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.os.Handler.dispatchMessage(Handler.java:99)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.os.Looper.loop(Looper.java:158)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at android.app.ActivityThread.main(ActivityThread.java:5789)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at java.lang.reflect.Method.invokeNative(Native Method)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at java.lang.reflect.Method.invoke(Method.java:525)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
 09-13 17:50:43.602   11372.11372                 Bundle  W     at dalvik.system.NativeStart.main(Native Method)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E  FATAL EXCEPTION: main
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E  java.lang.RuntimeException: Unable to resume activity {com.mycomp.myapp/com.facebook.LoginActivity}: java.lang.NullPointe
                                                             rException
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3228)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3266)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2579)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4258)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.access$700(ActivityThread.java:162)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1419)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.os.Handler.dispatchMessage(Handler.java:99)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.os.Looper.loop(Looper.java:158)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.main(ActivityThread.java:5789)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at java.lang.reflect.Method.invokeNative(Native Method)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at java.lang.reflect.Method.invoke(Method.java:525)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:843)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at dalvik.system.NativeStart.main(Native Method)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E  Caused by: java.lang.NullPointerException
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:135)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at com.facebook.LoginActivity.onResume(LoginActivity.java:117)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1282)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.Activity.performResume(Activity.java:5287)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3211)
 09-13 17:50:43.803   11372.11372         AndroidRuntime  E     ... 13 more
于 2013-09-13T09:54:11.843 回答
0

最近,我有同样的问题,但是,我从https://github.com/facebook/facebook-android-sdk将 facebook sdk 更新到 3.5.2 版本,有关登录的任何问题都已解决。

于 2013-10-18T14:13:25.010 回答