0

I'm trying to implement a Facebook share dialog in my app that will share my own app on Facebook. I downloaded facebook SDK and imported it in Android Studio. This is how I'm trying to do it.

First I followed these steps:

uiHelper = new UiLifecycleHelper(this, null);
uiHelper.onCreate(savedInstanceState);

 

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    uiHelper.onActivityResult(requestCode, resultCode, data, new FacebookDialog.Callback() {
        @Override
        public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) {
            Log.i("Activity", "Success!");
        }

        @Override
        public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) {
            Log.e("Activity", String.format("Error: %s", error.toString()));
        }
    });
}

I then also implemented the onResume, onDestroy etc.

And this is what happens when I click a button to share over facebook:

FacebookDialog shareDialog = new FacebookDialog.ShareDialogBuilder(this)
                    .setLink("https://play.google.com/store/apps/details?id="+getPackageName())
                    .build();
            uiHelper.trackPendingDialogCall(shareDialog.present());

However, when I run the app, it instantly crashes and this is the logcat output.

Caused by: java.lang.NullPointerException: Argument 'applicationId' cannot be null
        at com.facebook.internal.Validate.notNull(Validate.java:29)
        at com.facebook.Session.<init>(Session.java:281)
        at com.facebook.Session.<init>(Session.java:266)
        at com.facebook.UiLifecycleHelper.onCreate(UiLifecycleHelper.java:92)
        at com.mhacinapps.sleepwithnaturesounds.MainActivity.onCreate(MainActivity.java:47)

This is MainActivity.java:47

uiHelper = new UiLifecycleHelper(this, null);

I then registered the app to facebook so I got the app ID and I tried replacing "null" with the app ID. But when I do that, it says "integer number too large".

If someone could help me, I would greatly appreciate it. All I want to implement is a simple Share button so that the user can share the application link over facebook instantly.

Am I going to need facebook login for this?

Guy
  • 6,414
  • 19
  • 66
  • 136
  • 1
    Refer this link http://stackoverflow.com/questions/16156856/android-facebook-applicationid-cannot-be-null it might help you. Check your manifest – Gautam Aug 15 '14 at 11:57
  • Wow, thank you! This solved my problem. If you want to, you can post this as an answer and I'll accept it. – Guy Aug 15 '14 at 14:48

1 Answers1

0

Check your manifest and refer this link here - Android facebook applicationId cannot be null. Moreover i think its the manifest so i am giving the code of manifest file here as well .

<application
    android:icon="@drawable/icon"
    android:label="@string/app_name">
    <activity
        android:name=".ContactSelection"
        android:label="@string/app_name">
        <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:label="@string/app_name" />

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id" />
</application>
Community
  • 1
  • 1
Gautam
  • 3,252
  • 3
  • 23
  • 32