【发布时间】:2015-02-20 09:38:40
【问题描述】:
好的,所以我正在开发实现 facebook 登录的应用程序。
我遵循了 facebook 页面上的登录教程,实施很好,并且可以使用我的 facebook 帐户和其他几个帐户(我已经在 google play 上发布了我的应用程序),但不是全部。
Facebook 批准了我的权限请求,它们都已上线,我的应用也已上线。
用户在检索电子邮件或位置时收到空指针异常并且应用程序崩溃。
我尝试了什么:
- 检查了 oncomplete 方法中的权限,权限很好
- 其中一位崩溃的用户已将电子邮件设置为公开,所以这应该不是问题
如何解决这个问题,我应该检查什么?
这是我的代码:
private final List<String> permissions;
public LoginScreen() {
permissions = Arrays.asList("public_profile", "email","user_location","user_birthday");
}
LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);
authButton.setReadPermissions(permissions);
authButton.setFragment(this);
private void onSessionStateChange(Session session, SessionState state,
Exception exception) {
if (state.isOpened()) {
// Request user data and show the results
if (mSession == null || isSessionChanged(session)) {
mSession = session;
Request.newMeRequest(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Log.v("gj1",Session.getActiveSession().getPermissions().toString());
Log.v("gj1","stateopen");
name=user.getFirstName();
surname=user.getLastName();
Object objEmail=user.getProperty("email");
if(objEmail!=null)
{
mail=user.getProperty("email").toString();
}
else
{
Object objCmail=user.getProperty("contact_email");
if(objCmail!=null)
{
mail=user.getProperty("contact_email").toString();
}
else
{
mail="null@mail.com";
}
}
gender=user.getProperty("gender").toString();
city="N/A";
username=name+surname+user.getId();
password=user.getId();
if(gender.equals("male"))
{
interested="F";
}
else
{
interested="M";
}
if(user.getProperty("birthday")!=null) {
String dateFromDB = user.getProperty("birthday").toString();
username=name+surname+user.getProperty("birthday");
SimpleDateFormat parser = new SimpleDateFormat("MM/dd/yyyy");
try {
Date yourDate = parser.parse(dateFromDB);
Calendar calendar = Calendar.getInstance();
calendar.setTime(yourDate);
Calendar now = Calendar.getInstance();
age = now.get(Calendar.YEAR) - calendar.get(Calendar.YEAR);
} catch (ParseException e) {
e.printStackTrace();
}
}
else
{
age=0;
}
GraphPlace userLocation = user.getLocation();
city = (userLocation != null)? userLocation.toString() : "N/A";
}
}
}
}).executeAsync();
}
} else if (state.isClosed()) {
}
}
错误
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
at com.apps.medico.location_matchup.LoginScreen$5.onCompleted(LoginScreen.java:339)
at com.facebook.Request$1.onCompleted(Request.java:281)
at com.facebook.Request$4.run(Request.java:1666)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
我应该提供更多代码吗?
【问题讨论】:
-
如果您可以在您的环境中重现错误,发布 logcat 会有所帮助
-
我添加了 logcat 代码,这个错误发生在我用 if 包装有问题的代码之前
标签: android facebook performance facebook-graph-api