The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first
12,153
The docs have you set it in the Application class now:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize the SDK before executing any other operations,
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
}
}
https://developers.facebook.com/docs/android/getting-started/
Comments
-
Misters about 2 years
I have this error when implementing the Facebook SDK and i tried - many of the - solutions but none of then worked. This is what i have:
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); FacebookSdk.sdkInitialize(getApplicationContext()); callbackManager = CallbackManager.Factory.create(); setContentView(R.layout.activity_name_layout); LoginButton loginButton = (LoginButton)findViewById(R.id.fb_login_button); loginButton.setReadPermissions(Arrays.asList("public_profile", "email")); loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { @Override public void onSuccess(LoginResult loginResult) { } @Override public void onCancel() { } @Override public void onError(FacebookException error) { } }); @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); callbackManager.onActivityResult(requestCode, resultCode, data); }
Graddle:
compile 'com.facebook.android:facebook-android-sdk:4.8.0'
Manifest:
<activity android:name="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name" />
Layout button:
<LinearLayout xmlns:facebook="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:background="@color/colorPrimaryDark" android:padding="10dp" android:layout_height="match_parent"> <com.facebook.login.widget.LoginButton android:layout_marginTop="10dp" android:id="@+id/fb_login_button" android:layout_width="match_parent" android:layout_height="wrap_content" ></com.facebook.login.widget.LoginButton> </LinearLayout>
Can someone point me out what im doing wrong?
-
datWooWoo almost 6 yearsIt's deprecated, and yet you get an error saying "You must call FacebookSdk.sdkInitialize() first". lol good lord Facebook.