Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Android SDK & java.lang.NullPointerException

I am having trouble opening an active facebook session in my android app as per the tutorial posted at https://developers.facebook.com/docs/android/getting-started/facebook-sdk-for-android/

I have been struggling with this for quite some time now without any luck! I will be glad if one of you would point me in the right direction! (I bet the error is with some setup on my side, but I am unable to spot it)

Here is the error I am seeing after calling Session.openActiveSession(this, true, new Session.StatusCallback() in the onCreate of my activity (I am pretty much following the steps given in facevook developer tutorials)


EDIT : The following warning message is logged first and followed by the error message in the subsequent screen shot

09-03 19:26:22.726: W/Bundle(17458): Key com.facebook.platform.protocol.PROTOCOL_VERSION expected String but value was a java.lang.Integer. The default value was returned. 09-03 19:26:22.736: W/Bundle(17458): Attempt to cast generated internal exception: 09-03 19:26:22.736: W/Bundle(17458): java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String 09-03 19:26:22.736: W/Bundle(17458): at android.os.Bundle.getString(Bundle.java:1061) 09-03 19:26:22.736: W/Bundle(17458): at android.content.Intent.getStringExtra(Intent.java:4466) 09-03 19:26:22.736: W/Bundle(17458): at com.facebook.AuthorizationClient$KatanaLoginDialogAuthHandler.tryAuthorize(AuthorizationClient.java:821) 09-03 19:26:22.736: W/Bundle(17458): at com.facebook.AuthorizationClient.tryCurrentHandler(AuthorizationClient.java:272)

enter image description here


09-02 22:55:04.110: E/AndroidRuntime(13287): FATAL EXCEPTION: main 09-02 22:55:04.110: E/AndroidRuntime(13287): java.lang.RuntimeException: Unable to resume activity {com.good.amrfbintegration/com.facebook.LoginActivity}: java.lang.NullPointerException 09-02 22:55:04.110: E/AndroidRuntime(13287): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3036) 09-02 22:55:04.110: E/AndroidRuntime(13287): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3077) 09-02 22:55:04.110: E/AndroidRuntime(13287): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2373)

enter image description here

Here is what I have done so far

Updated the App on Facebook with the following information (I have used the hashkey generated using my machine's debug keystore)

enter image description here

Here are the relevant info from my manifest file (@string/app_id is the App Id from facebook dev portal)

enter image description here

I added a reference to the Facebook SDK to my project in this way

enter image description here

Here is the code in my OnCreate method of the main activity

@Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        activity = this;

        Session.openActiveSession(this, true, new Session.StatusCallback() 
        {
            @Override
            public void call(Session session, SessionState state, Exception exception)
            {               
                if (session.isOpened())
                {
                    Toast.makeText(activity, "Connected to Fb", Toast.LENGTH_SHORT).show();
                }
            }});
        }

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

On executing the Session.openActiveSession, logcat display the error shown in my first screenshot.

The Session.StatusCallback()'s call method gets executed once (while session has a state 'opening') but the app crashes the subsequent time. here is what I see before the App crashes

enter image description here

Any assistance would be greatly appreciated!

like image 375
infinity Avatar asked Sep 03 '13 04:09

infinity


2 Answers

This problem because of Facebook SDK, please download and use Facebook SDK 3.5.2 from this URL:-https://developers.facebook.com/docs/android/

like image 152
Venkat Avatar answered Oct 09 '22 01:10

Venkat


Yes. Check your code,

Make sure, you have these things on Manifest.xml

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

And @string/app_id should contain the app_id that you get from your facebook app configuration details. Also there you should put the correct keyhash.

So make sure -

  1. your key hash is correct
  2. You have configured app correctly on web, and taken care of putting the app id in your app configuration.
like image 20
AnhSirk Dasarp Avatar answered Oct 09 '22 00:10

AnhSirk Dasarp