Android facebook applicationId cannot be null

I followed the next tutorial to integrate my application with Facebook. Facebook tutorial

I followed everything in the tutorial, but I got applicationId cannot be null in two cases, and it really upset.

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 action, I get applicationId cannot be null , and the LogCat line points me to: uiHelper.onCreate(savedInstanceState);

So, I tried to comment on this line, and the activity is displayed. However, now when I click on LoginButton , I get the same error, but this time I specify the applicationId field in the LoginButton class from facebook.

I already have an Id in my string values, and my manifest looks like this:

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

I tried to get the code using the id, but nothing changed.

What exactly causes all this?

+70
android facebook
Apr 22 '13 at 21:15
source share
5 answers

TL; DR: you have to write your application ID in strings.xml and then a link (i.e. @strings/fb_app_id ), because if you put it directly (as a value) in AndroidManifest.xml this will not work.

You must define your applicationId in AndroidManifest.xml for example:

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

under the tag <application android:label="@string/app_name"....

where app_id is the string in your strings.xml .




Example:

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

** note that <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> is in the <application>

- and in strings.xml

 <string name="app_id">1389xxxxxxxx</string> 
+225
April 22. '13 at 21:19
source share
β€” -

From today, the answer is not entirely correct. If someone has not used this: AppEventsLogger.activateApp(this);

Since the last update, you must do this or your application will be broken. And you must also pass the Application here Context

https://developers.facebook.com/docs/android/getting-started

 // Add this to the header of your file: import com.facebook.FacebookSdk; public class MyApplication extends Application { // Updated your class body: @Override public void onCreate() { super.onCreate(); // Initialize the SDK before executing any other operations, FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(this); } } 
+8
Jun 16 '16 at 22:48
source share

The problem is that the id is converted to an integer: https://code.google.com/p/android/issues/detail?id=78839

In my case, facebook_app_id set from the build.gradle file for each flavor.

The solution was to wrap the identifier with " :

 flavor.resValue "string", "facebook_app_id", "\"1111111111111\"" 

or if you prefer to avoid shielding:

 flavor.resValue "string", "facebook_app_id", '"1111111111111"' 
+7
Apr 08 '15 at 16:01
source share

This little code modification in action helped me.

 @Override protected void onCreate(Bundle savedInstanceState) { FacebookSdk.sdkInitialize(getApplicationContext()); AppEventsLogger.activateApp(getApplication()); super.onCreate(savedInstanceState); ................... ................... } 
0
Jun 17 '16 at 8:39
source share

Actually you do not need to use taste codes in gradle ...

if you have a number greater than 4 bytes, this code should be specified in the strings.xml file

Note : pay attention to this quotation mark ( " )

 <string name="facebook_app_id">"1111111111111"</string> 
-one
Jun 07 '15 at 23:09
source share



All Articles