4

I am trying to login into facebook using parse. Below is my code.

Button fbLoginButton = (Button)findViewById(R.id.login_facebook);
final List<String> permission = Arrays.asList("public_profile", "User_friends");
        fbLoginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ParseFacebookUtils.logInWithReadPermissionsInBackground(MainActivity.this, permission, new LogInCallback() {
                    @Override
                    public void done(ParseUser parseUser, ParseException e) {
                        if(parseUser == null) {
                            Log.d("ParseUser" , "User cancelled login");
                        } else if(parseUser.isNew()) {
                            Log.d("New User", "User signed up and logged in using facebook");
                        } else {
                            Log.d("ParseUser", "user logged in using facebook");
                        }
                    }
                } );
            }
        });

I am getting java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference while running the app. In the log its also showing that the error is at line 146. at com.example.gopi.layouts_test.MainActivity$2.onClick(MainActivity.java:146)

Line number 146 in my code is ParseFacebookUtils.logInWithReadPermissionsInBackground(MainActivity.this, permission, new LogInCallback() {

I tried hashing out the first if condition like below.

/*if(parseUser == null) {
                            Log.d("ParseUser" , "User cancelled login");
                        } else */

Still I am getting the same error at same line number.

Full Stack trace:

04-30 05:38:25.763    1233-1233/com.example.gopi.layouts_test E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.gopi.layouts_test, PID: 1233
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
            at com.facebook.login.LoginManager.getLogger(LoginManager.java:391)
            at com.facebook.login.LoginManager.logCompleteLogin(LoginManager.java:414)
            at com.facebook.login.LoginManager.startLogin(LoginManager.java:384)
            at com.facebook.login.LoginManager.logInWithReadPermissions(LoginManager.java:262)
            at com.parse.FacebookAuthenticationProvider.authenticateAsync(FacebookAuthenticationProvider.java:155)
            at com.parse.ParseAuthenticationProvider.logInAsync(ParseAuthenticationProvider.java:50)
            at com.parse.ParseFacebookUtils.logInAsync(ParseFacebookUtils.java:265)
            at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:161)
            at com.parse.ParseFacebookUtils.logInWithReadPermissionsInBackground(ParseFacebookUtils.java:173)
            at com.example.gopi.layouts_test.MainActivity$2.onClick(MainActivity.java:146)
            at android.view.View.performClick(View.java:4780)
            at android.view.View$PerformClick.run(View.java:19866)
            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:5254)
            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:903)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

Please help me.

1
  • 2
    Can you post the entire stack trace? Commented Apr 30, 2015 at 0:09

2 Answers 2

15

I have include the meta-data tag inside the application tag in manifest, which resolved the issue.

Include the following inside application tag.

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

Thanks

Sign up to request clarification or add additional context in comments.

2 Comments

This, and adding the FacebookActivity to the manifest helped. Great.
makes sense, error description could be way better from facebook
1

I think you're missing the implementation of onActivityResult in your relevant activity.

Try adding:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}

1 Comment

I have already overridden the onActivityResult() method in MainActivity class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.