我的应用程序在模拟器上运行良好。所以我决定在我的安卓手机上运行我的应用程序。我正在尝试使用我的应用程序登录 Facebook 帐户,它在模拟器上运行良好。一旦我在安卓手机上运行我的应用程序,我总是会得到这个异常 -
01-30 11:06:08.400: E/AndroidRuntime(7463): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=0, data=null} to activity {com.facebook.samples.sessionlogin/com.facebook.LoginActivity}: java.lang.NullPointerException
下面是我的代码-
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
buttonLoginLogout = (Button) view.findViewById(R.id.buttonLoginLogout);
textInstructionsOrLink = (TextView) view.findViewById(R.id.instructionsOrLink);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = Session.getActiveSession();
if (session == null) {
if (savedInstanceState != null) {
session = Session.restoreSession(getActivity(), null, statusCallback,
savedInstanceState);
}
if (session == null) {
session = new Session(getActivity());
}
Session.setActiveSession(session);
if (session.getState().equals(SessionState.CREATED_TOKEN_LOADED)) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
}
}
updateView();
return view;
}
@Override
public void onStart() {
super.onStart();
Session.getActiveSession().addCallback(statusCallback);
}
@Override
public void onStop() {
super.onStop();
Session.getActiveSession().removeCallback(statusCallback);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Session.getActiveSession().onActivityResult(getActivity(), requestCode, resultCode, data);
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Session session = Session.getActiveSession();
Session.saveSession(session, outState);
}
private void updateView() {
Session session = Session.getActiveSession();
if (session.isOpened()) {
Intent thesisProject = new Intent(getActivity(), ThesisProjectAndroid.class);
startActivity(thesisProject);
} else {
Log.d(TAG_LOGIN_FAILED,
"There is something wrong with your Facebook account. Please try again.");
textInstructionsOrLink.setText(R.string.instructions);
buttonLoginLogout.setText(R.string.login);
buttonLoginLogout.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
onClickLogin();
}
});
}
}
private void onClickLogin() {
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));
} else {
Session.openActiveSession(getActivity(), this, true, statusCallback);
}
}
private void onClickLogout() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}
private class SessionStatusCallback implements Session.StatusCallback {
@Override
public void call(Session session, SessionState state, Exception exception) {
updateView();
}
}
我正在做的是-一旦我使用 Facebook 帐户登录,我需要转到另一个 Intent(在模拟器中运行良好)但是一旦我在 android 手机中安装了这个应用程序,我总是会Login failed
尽快当应用程序启动时,我什至没有在 facebook 登录页面上提供用户名和密码,而且我得到了上述异常。
还有谁能让我知道我的逻辑是否正确updateView method
-我想做的是,只要 Facebook 身份验证正确意味着我可以登录,那么我需要转到另一个 Intent。
任何人都可以在这里帮助我,为什么会发生这种情况?