简体   繁体   中英

NullPointerException when logging in with Facebook SDK and ParseFacebookUtils

We are using Parse SDK and trying to login with Facebook function. But we could not figure it out. We get NullPointerException. What's wrong with our implementation?

Our SDK versions we used: Parse SDK 1.10.3 , Facebook SDK 4.7.0 , ParseFacebookUtilsV4-1.10.3

Stacktrace :

11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.login.LoginClient.getLogger(LoginClient.java:363)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.login.LoginClient.logAuthorizationMethodComplete(LoginClient.java:413)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.login.LoginClient.tryNextHandler(LoginClient.java:196)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.login.GetTokenLoginMethodHandler.getTokenCompleted(GetTokenLoginMethodHandler.java:119)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.login.GetTokenLoginMethodHandler$1.completed(GetTokenLoginMethodHandler.java:74)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.internal.PlatformServiceClient.callback(PlatformServiceClient.java:157)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.internal.PlatformServiceClient.handleMessage(PlatformServiceClient.java:141)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.facebook.internal.PlatformServiceClient$1.handleMessage(PlatformServiceClient.java:62)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:145)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5834)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
11-08 15:27:34.507 8983-8983/com.taurus.trolley E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)

We added this code below to manifest.

AndroidManifest.xml:

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

<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" />

We added this code below to Application#onCreate() method.

Application#onCreate():

    // Facebook SDK initializing
    FacebookSdk.sdkInitialize(getApplicationContext());

    // Enable Local Datastore.
    Parse.enableLocalDatastore(this);

    Parse.initialize(this, PARSE_APP_ID, PARSE_CLIENT_KEY);
    ParseFacebookUtils.initialize(this);

The code that provides login function:

    List<String> permissions = Arrays.asList("public_profile", "email");

    ParseFacebookUtils.logInWithReadPermissionsInBackground(this, permissions, new LogInCallback() {
        @Override
        public void done(ParseUser user, ParseException e) {
            if (user == null) {
                Log.d(TAG, "Uh oh. The user cancelled the Facebook login.");
            } else if (user.isNew()) {
                Log.d(TAG, "User signed up and logged in through Facebook!");
            } else {
                Log.d(TAG, "User logged in through Facebook!");
            }
        }
    });

I had the same issue. After waiting for a while, it works flawlessly. So, I think FB need to do something when 1st you login.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM