14

I started to work with facebook-android-sdk-3.5.2.

The SDK project also contains varius sample examples for using the api like:

  • HelloFacebookSample: A simple activity you can log in and do stuff, it works great.

Next thing i wanted to try the next example called:

  • GraphApiSample, which i had problem with.

After i launch this app, i got this error: (Logcat):

11-11 15:22:40.008: E/AndroidRuntime(14048): FATAL EXCEPTION: main
11-11 15:22:40.008: E/AndroidRuntime(14048): java.lang.RuntimeException: Unable to resume activity {com.facebook.samples.graphapi/com.facebook.samples.graphapi.GraphApiSampleActivity}: java.lang.IllegalArgumentException: Both context and applicationId must be non-null
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2621)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2649)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread.access$700(ActivityThread.java:134)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.os.Looper.loop(Looper.java:137)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread.main(ActivityThread.java:4867)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at java.lang.reflect.Method.invokeNative(Native Method)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at java.lang.reflect.Method.invoke(Method.java:511)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at dalvik.system.NativeStart.main(Native Method)
11-11 15:22:40.008: E/AndroidRuntime(14048): Caused by: java.lang.IllegalArgumentException: Both context and applicationId must be non-null
11-11 15:22:40.008: E/AndroidRuntime(14048):    at com.facebook.AppEventsLogger.activateApp(AppEventsLogger.java:308)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at com.facebook.AppEventsLogger.activateApp(AppEventsLogger.java:292)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at com.facebook.samples.graphapi.GraphApiSampleActivity.onResume(GraphApiSampleActivity.java:76)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1199)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.Activity.performResume(Activity.java:5121)
11-11 15:22:40.008: E/AndroidRuntime(14048):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2611)

Well i see:

Caused by: java.lang.IllegalArgumentException: Both context and applicationId must be non-null

Okay, but i did not changed a thing in the code. It should be work, right?

I tried to:

  • Delete project, and import

  • Delete project, and add a new android project from existing code

  • Clean my project

  • Delete facebook sdk library dependency and reimport, then clean again.

Same result after all of these.

Please if somebody is familiar with this prob. help me.

E D I T:

For some reason, this official facebook sample does not contains appId. Thanks for the suggest!

Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222

2 Answers2

24

Try to set the app_id in the strings.xml or add it. It is also mentioned in the getting started tutorial here: Documentation

An additional step: Create a meta-data with the name com.facebook.sdk.ApplicationId and the value @string/app_id in AndroidManifest.xml

A.S.
  • 4,574
  • 3
  • 26
  • 43
5

If you don't have (or want) the facebook app id stored in your strings.xml (e.g., maybe you receive the facebook app id dynamically over the internet), then you can call this method instead to activate... AppEventsLogger.activateApp(Context context, String facebookAppId)

You should call this in the onResume() method of your activities:

@Override protected void onResume() { super.onResume(); AppEventsLogger.activateApp(...); }

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
  • Where is the best place to call the method? – Jorge Gil Jul 03 '15 at 15:54
  • 1
    You should add it in the `onResume()` method of your activity. I've updated my answer with a code snippet. – ban-geoengineering Jul 08 '15 at 17:13
  • I have an applicationID and I followed the steps (put it in strings.xml and in manifest.xml) but still got the error. Any idea why? In the meantime, your suggestion allowed me to continue developing my app (gave you +1) – Zvi Mar 26 '16 at 12:00
  • Hiya Zvi, Not sure, really. You'd be best off posting a new question with your appropriate code and stack trace. :-) – ban-geoengineering Mar 27 '16 at 16:17