NullPointerException when logging into facebook using LoginManager.Instance.LoginWithReadPermission

I've created a post on stack overflow about this error so I will just post the link here.

http://stackoverflow.com/questions/38474039/java-lang-nullpointerexception-xamarin-facebook-android-sdk

I've tried just doing everything into MainActivity.cs, but I'm still facing the same Null Pointer Exception error and I have no clue right now. Please help.

Answers

  • AnoimusAnoimus USMember

    When I mean I'm doing everything in Main Activity.cs

    I mean trying to login the user immediately on onCreate, but ultimately I would want to log in with a custom button in my app itself but I can't log in now without getting the Null Pointer Exception error
    public class MainActivity : AndroidGameActivity, IFacebookCallback
    {
    static readonly string [] ReadPermissions = new [] { "public_profile" };

            ICallbackManager callbackManager;
        protected override void OnCreate (Bundle savedInstanceState)
        {
    
            base.OnCreate (savedInstanceState);
            var g = new Game1();
    
            callbackManager = CallbackManagerFactory.Create ();
            FacebookSdk.SdkInitialize (this.ApplicationContext);
    
    
            LoginManager.Instance.RegisterCallback (callbackManager, this);
    
            LoginManager.Instance.LogInWithReadPermissions (this, ReadPermissions);
    
            SetContentView(g.Services.GetService<View>());
    
    
            g.Run();
        }
    
        protected override void OnActivityResult (int _requestCode, Result _resultCode, Intent _intent)
                {
                    callbackManager.OnActivityResult(_requestCode, (int)_resultCode, _intent);
                    base.OnActivityResult (_requestCode, _resultCode, _intent);
                }
    
                public void OnCancel ()
                {
                    Console.WriteLine ("User canceled");
                }
    
                public void OnError (FacebookException p0)
                {
                    Console.WriteLine (p0);
                }
    
                public void OnSuccess (Java.Lang.Object p0)
                {
                    LoginResult loginResult = p0 as LoginResult;
                    Console.WriteLine (loginResult.AccessToken.UserId);
                }
    }
    
Sign In or Register to comment.