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 ...




8 comments:

  1. thanks, i'll try.
    I'm having this issue

    ReplyDelete
  2. I'm having the same problem, but I'm inserting metadata tag aparently right:





    so, I receive "argument applicationid cannot be null", can you help me please?

    ReplyDelete
  3. Thanks,I resolve this but,
    another error I am getting is Noclassdeffound in loginactivity of facebook
    Please help

    ReplyDelete
  4. Hi Prachi,
    I think you have not specified activity android name com.facebook.LoginActivity in your project manifest file.
    Hope it helps.

    ReplyDelete
  5. Hello, I have refer app id using string value still i am getting same null poiner error. have some solution?

    ReplyDelete
  6. thank you very much .really this is very helpful

    ReplyDelete