Saturday, November 23, 2013

Facebook Android integration java.lang.NullPointerException: Argument 'applicationId' cannot be null

You may face the following error when integrating facebook sdk with Android :

                java.lang.NullPointerException: Argument 'applicationId' cannot be null.

If you are getting the above error even though you specified the facebook applicationId in manifest file as follows: 

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


Reason:
Reason for the above error is due to the ApplicationId is mentioned as Integer , as we specified directly in manifest . But facebook SDK needs ApplicationId value as String. So if we pass ApplicationId as above, inside facebook SDK 'ClassCastException' occurs and considers  ApplicationId value as null. 

Solution:
Declare APP_ID value in strings.xml as follows:
 <string name="APP_ID">123456785678</string>

And then refer this APP_ID as ApplicationId value in manifest file:

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

Please share your comments on this , if it is helped ...