我可以成功连接到 facebook 并获得好友列表。所有连接都正常。但是当我删除 Facebook 的数据(通过设置-> 应用程序)和我的应用程序时,会出现登录问题。[SDK 3.5]
- 启动我的应用
- 建立脸书连接
- Facebook 要求输入用户名和密码,输入它们
- 等一下
- 它显示要求基本用户信息和错误发生的权限屏幕:“您的应用程序意外停止工作。请重试(强制关闭)”
当我单击强制关闭时,突然一次又一次地发生相同的错误(而权限屏幕仍在后面)。如果我够快,我单击强制关闭,然后单击允许权限,一切正常,我可以看到我的朋友。所以这个 FORCE CLOSE 错误意味着什么都没有?在日志中,有 3-4 条相同的 Fatal Exception 消息,因为每次单击 FORCE CLOSE 都会再次出现错误。当我在手机上尝试应用程序时出现此错误(SE Xperia Arc S,2.3.3)。但是当我尝试使用模拟器时,错误不会发生。它可以正常工作。(模拟器是 2.3.3 和 4.2)
09-04 18:09:47.916 E/AndroidRuntime(29511): FATAL EXCEPTION: main
09-04 18:09:47.916 E/AndroidRuntime(29511): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:47.916 E/AndroidRuntime(29511): Caused by: java.lang.NullPointerException
09-04 18:09:47.916 E/AndroidRuntime(29511): ... 12 more
09-04 18:09:51.526 E/AndroidRuntime(29538): FATAL EXCEPTION: main
09-04 18:09:51.526 E/AndroidRuntime(29538): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:51.526 E/AndroidRuntime(29538): Caused by: java.lang.NullPointerException
09-04 18:09:51.526 E/AndroidRuntime(29538): ... 12 more
09-04 18:09:53.786 E/AndroidRuntime(29547): FATAL EXCEPTION: main
09-04 18:09:53.786 E/AndroidRuntime(29547): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:53.786 E/AndroidRuntime(29547): Caused by: java.lang.NullPointerException
09-04 18:09:53.786 E/AndroidRuntime(29547): ... 12 more
09-04 18:09:55.516 E/AndroidRuntime(29557): FATAL EXCEPTION: main
09-04 18:09:55.516 E/AndroidRuntime(29557): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:55.516 E/AndroidRuntime(29557): Caused by: java.lang.NullPointerException
09-04 18:09:55.516 E/AndroidRuntime(29557): ... 12 more
09-04 18:09:57.776 E/AndroidRuntime(29564): FATAL EXCEPTION: main
09-04 18:09:57.776 E/AndroidRuntime(29564): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:57.776 E/AndroidRuntime(29564): Caused by: java.lang.NullPointerException
09-04 18:09:57.776 E/AndroidRuntime(29564): ... 12 more
09-04 18:09:59.186 E/dalvikvm(29571): Could not find class 'dalvik.system.BaseDexClassLoader', referenced from method com.facebook.common.dextricks.SystemClassLoaderAdder.a
09-04 18:09:59.586 E/dalvik-internals(29571): Failed to look up ladDumpProfiles
09-04 18:09:59.586 E/dalvik-internals(29571): Failed to look up ladResetProfiles
09-04 18:09:59.586 E/dalvik-internals(29571): Failed to look up ladPrintHeaderInfo
09-04 18:09:59.936 E/AndroidRuntime(29578): FATAL EXCEPTION: main
09-04 18:09:59.936 E/AndroidRuntime(29578): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:09:59.936 E/AndroidRuntime(29578): Caused by: java.lang.NullPointerException
09-04 18:09:59.936 E/AndroidRuntime(29578): ... 12 more
09-04 18:10:02.006 E/AndroidRuntime(29585): FATAL EXCEPTION: main
09-04 18:10:02.006 E/AndroidRuntime(29585): java.lang.RuntimeException: Unable to resume activity {com.ilanharitasi/com.facebook.LoginActivity}: java.lang.NullPointerException
09-04 18:10:02.006 E/AndroidRuntime(29585): Caused by: java.lang.NullPointerException
09-04 18:10:02.006 E/AndroidRuntime(29585): ... 12 more
09-04 18:10:04.566 E/ONRESUME(29605): Onresume worked
09-04 18:10:04.636 E/STATEM (29605): OPENING
09-04 18:10:05.186 E/ONRESUME(29605): Onresume worked
第一次连接后,我可以找到我的朋友,没有任何错误。它只发生在我第一次连接 Facebook 并询问我的用户名和密码(然后单击登录)之后
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.activity_fb_findfriends);
LinearLayout v = (LinearLayout) findViewById(R.id.fb_app_users);
openSession(v);
}
public void openSession(View v){
// start Facebook Login
Session.openActiveSession(this, true, callback);
}
@Override
protected void onResume() {
super.onResume();
uiHelper.onResume();
Log.e("ONRESUME", "Onresume çalıştı");
}
private void requestMyAppFacebookFriends(Session session) {
Request friendsRequest = createRequest(session);
friendsRequest.setCallback(new Request.Callback() {
@Override
public void onCompleted(Response response) {
List<GraphUser> friends = getResults(response);
//Display Friends
}
});
friendsRequest.executeAsync();
}
我也无法理解日志输出中的 null 值。
更新!我找到了发生错误的行。它在 com.facebook.AuthorizationClient.java 第 135 行内
void startOrContinueAuth(AuthorizationRequest request) {
if (appEventsLogger == null || appEventsLogger.getApplicationId() != request.getApplicationId()) {
Log.e("HATA!", "BOOM");
appEventsLogger = AppEventsLogger.newLogger(context, request.getApplicationId());
}
这个 startOrContinueAuth 方法是在 com.Facebook.LoginActivity 中触发的
@Override
public void onResume() {
super.onResume();
// If the calling package is null, this generally means that the callee was started
// with a launchMode of singleInstance. Unfortunately, Android does not allow a result
// to be set when the callee is a singleInstance, so we log an error and return.
if (callingPackage == null) {
Log.e(TAG, "Aheyy"+NULL_CALLING_PKG_ERROR_MSG);
finish();
return;
}
authorizationClient.startOrContinueAuth(request);
}
if (getInProgress()) {
continueAuth();
} else {
authorize(request);
}
}
更新 2!
- 我很困惑。我将我的应用程序简化为非常基本的 openActiveSession() 方法。崩溃
- 我尝试了 Facebook、FriendPicker 的示例应用程序,它也因相同的日志错误输出而崩溃。
- 在模拟器上试过,它可以工作,但是当我在授权屏幕出现时旋转屏幕(取消允许)时,发生同样的错误(无法 onResume 等等等等......)在 Facebook 的示例应用程序上出现同样的错误很奇怪