解析facebook登录空指针异常

时间:2015-08-28 19:26:03

标签: android facebook parse-platform nullpointerexception

我试图在我的andorid应用程序上使用parse登录facebook,但是我收到以下错误:

  

08-28 21:24:34.441 10524-10524 / com.example.hristijan.likeout E / AndroidRuntime:FATAL EXCEPTION:main       处理:com.example.hristijan.likeout,PID:10524       java.lang.NullPointerException:尝试调用虚方法' boolean java.lang.String.equals(java.lang.Object)'在null对象引用上               在com.facebook.login.LoginManager.getLogger(LoginManager.java:391)               在com.facebook.login.LoginManager.logCompleteLogin(LoginManager.java:414)               在com.facebook.login.LoginManager.startLogin(LoginManager.java:384)               在com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:262)               在com.parse.FacebookAuthenticationProvider.authenticateAsync(FacebookAuthenticationProvider.java:150)               at com.parse.ParseAuthenticationProvider.logInAsync(ParseAuthenticationProvider.java:57)               在com.parse.ParseFacebookUtils.logInAsync(ParseFacebookUtils.java:259)               在com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:155)               at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:167)               在com.example.hristijan.likeout.MainActivity.facebookLogin(MainActivity.java:74)               在com.example.hristijan.likeout.MainActivity $ 3.onClick(MainActivity.java:67)               在android.view.View.performClick(View.java:4763)               在android.view.View $ PerformClick.run(View.java:19821)               在android.os.Handler.handleCallback(Handler.java:739)               在android.os.Handler.dispatchMessage(Handler.java:95)               在android.os.Looper.loop(Looper.java:135)               在android.app.ActivityThread.main(ActivityThread.java:5274)               at java.lang.reflect.Method.invoke(Native Method)               在java.lang.reflect.Method.invoke(Method.java:372)               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:909)               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)

以下是代码:

ParseFacebookUtils.logInWithReadPermissionsInBackground(this, null, new LogInCallback() {
        @Override
        public void done(ParseUser user, ParseException e) {
            if (user == null) {
                //Canceled fb connection
                Toast.makeText(getApplicationContext(), "CANCEL", Toast.LENGTH_LONG).show();
            } else if (user.isNew()) {
                //Registered with fb
                Toast.makeText(getApplicationContext(), "REGISTERED", Toast.LENGTH_LONG).show();
            } else {
                //Logged in with fb
                Toast.makeText(getApplicationContext(), "LOGGED IN", Toast.LENGTH_LONG).show();
            }
        }
    });

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,为了解决此问题,您需要在androidmanifest.xml上添加此问题,您可以在应用信息中心上获得facebook_app_id

<meta-data
    android:name="com.facebook.sdk.ApplicationId"
    android:value="@string/facebook_app_id"/>

之后,我还需要添加FacebookActivity

    <activity android:name="com.facebook.FacebookActivity"
      android:configChanges=
             "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"
      android:label="@string/app_name" />

请记住将这些行放在application标记内。

找到解决方案here