I've been following the following tutorial to integrate my app with Facebook. Facebook tutorial
I've followed everything on the tutorial, but I've been getting applicationId cannot be null
in two cases, and it's really frustrating.
My FacebookActivity
onCreate
has the following, which is exactly the same as the tutorial:
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); uiHelper = new UiLifecycleHelper(this, callback); uiHelper.onCreate(savedInstanceState); setContentView(R.layout.main_fb); FragmentManager fm = getSupportFragmentManager(); fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment); fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment); FragmentTransaction transaction = fm.beginTransaction(); for(int i = 0; i < fragments.length; i++) { transaction.hide(fragments[i]); } transaction.commit(); }
However when I try to display the activity I get applicationId cannot be null
, and the line LogCat points me to is: uiHelper.onCreate(savedInstanceState);
So then I tried commenting out that line, and the activity is displayed. However now when I click on the LoginButton
, I get the same error but this time is points me to the applicationId field in the LoginButton class from facebook.
I already have the Id in my string values and my manifest like this:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/APP_ID"/>
I tried getting the Id using code, but nothing changed.
What exactly is causing all this?
TL;DR: you have to write your application's ID in your
strings.xml
and then reference (i.e.@strings/fb_app_id
), because if you put it directly (as value) intoAndroidManifest.xml
it won't work.
you must define your applicationId
in the AndroidManifest.xml
like this:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
under <application android:label="@string/app_name"....
tag
where app_id
is a string within your strings.xml
.
sample:
<application android:label="@string/app_name" android:icon="@drawable/icon" android:theme="@android:style/Theme.NoTitleBar" > <activity android:name=".HelloFacebookSampleActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustResize"> <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> <activity android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name" /> <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> </application>
** please note <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
is within <application>
tag
-- and in strings.xml
<string name="app_id">1389xxxxxxxx</string>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With