App crashes after first Facebook Login

久未见 提交于 2019-12-09 05:52:45

问题


Sometimes (not very frequently) my android app crashes after first logging to facebook using Facebook Login (Facebook SDK version 3.5).

I'm getting exception:

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

with 2 different root exceptions:

Sometimes with:

java.lang.NullPointerException at com.facebook.AuthorizationClient.startOrContinueAuth(AuthorizationClient.java:135)

And sometimes:

Caused by: java.lang.NullPointerException at com.facebook.AuthorizationClient.logAuthorizationMethodComplete(AuthorizationClient.java:519)

In most cases my app is working fine.

Any ideas what may cause this problem?

EDIT:

My facebook sdk conf in manifest:

<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" />

Activity code:

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);
}

...

}

I also got this error with previous version of Facebook SDK. I have latest Fb android client. Any help?


回答1:


Facebook just released v3.5.1 of their Android SDK yesterday that addresses your issues. Their Change Log doesn't give much information about what went wrong, but people have been reporting this bug and they did say it would be fixed in a later version (source). But anyway, looking at the diffs between v3.5 and v3.5.1 they seem to have fixed code around lines 135 and 519. Check out the Change Log the complete list. Probably a good idea never to upgrade to a significant version from Facebook until they release their first patch to it.




回答2:


I got the same issue today. It seems Facebook SDK 3.5 might not be compatible with old Facebook clients such as Facebook 2.1. I updated Facebook client to the latest version and then it works.

 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



回答3:


Recently, I have same problem, however, I update the facebook sdk to 3.5.2 version from https://github.com/facebook/facebook-android-sdk and any problem about loggining have been solved.



来源:https://stackoverflow.com/questions/18752977/app-crashes-after-first-facebook-login

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