Official Facebook examples crashes (GraphApiSample)
Asked Answered
C

2

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!

Capsaicin answered 11/11, 2013 at 14:28 Comment(3)
try to set the app_id in the strings.xml or add itIndescribable
Add it as an answer and i will accept, thank you.Capsaicin
The current GraphApiSampleActivity has APP_ID defined in the class already. I used version 3.6.0 of the SDK.Barrus
I
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

Indescribable answered 12/11, 2013 at 7:3 Comment(0)
C
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(...); }

Conform answered 12/12, 2014 at 17:12 Comment(4)
Where is the best place to call the method?Nedranedrah
You should add it in the onResume() method of your activity. I've updated my answer with a code snippet.Conform
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)Withstand
Hiya Zvi, Not sure, really. You'd be best off posting a new question with your appropriate code and stack trace. :-)Conform

© 2022 - 2024 — McMap. All rights reserved.