App crashes after first Facebook Login
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?
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.
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
最近,我也遇到了同样的问题,但是,我从https://github.com/facebook/facebook-android-sdk更新了facebook sdk到3.5.2版本,并且任何有关登录的问题都已解决。
链接地址: http://www.djcxy.com/p/74308.html上一篇: Grep列表文件名和行号