Question

I setup whole new project and test code from guide https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ Everything went great, but I'm getting force close when I add this code to my own app.

  Session.openActiveSession(this, true, new Session.StatusCallback() { 

This line causes force close

Code

   @Override
 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.przegladaj_layout);

    // next line is 79, and makes force close
    Session.openActiveSession(this, true, new Session.StatusCallback() { 
        // callback when session changes state
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

                // make request to the /me API
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                    // callback after Graph API response with user object
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            TextView welcome = (TextView) findViewById(R.id.ulubionetv);
                            welcome.setText("Hello " + user.getName() + "!");
                        }
                    }
                });
            }
        }
    });

 /* rest of code */

  /* after onCreate */
@Override
   public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

AndroidManifest

    <uses-sdk
          android:minSdkVersion="8"
          android:targetSdkVersion="17" />
          <uses-permission android:name="android.permission.INTERNET"/>

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

Logcat output

         07-27 18:10:33.897: E/Trace(15621): error opening trace file: Permission denied (13)              
         07-27 18:10:34.413: E/AndroidRuntime(15621): FATAL EXCEPTION: main
         07-27 18:10:34.413: E/AndroidRuntime(15621): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at com.facebook.Session.postActiveSessionAction(Session.java:1215)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at com.facebook.Session.setActiveSession(Session.java:765)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at com.facebook.Session.openActiveSession(Session.java:865)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at com.facebook.Session.openActiveSession(Session.java:805)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at pl.evelan.law.murphy.ActPrzegladaj.onCreate(ActPrzegladaj.java:79)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.Activity.performCreate(Activity.java:5058)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2104)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2178)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.ActivityThread.access$700(ActivityThread.java:141)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1271)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.os.Handler.dispatchMessage(Handler.java:99)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.os.Looper.loop(Looper.java:137)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at android.app.ActivityThread.main(ActivityThread.java:5118)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at java.lang.reflect.Method.invokeNative(Native Method)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at java.lang.reflect.Method.invoke(Method.java:511)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
         07-27 18:10:34.413: E/AndroidRuntime(15621):   at dalvik.system.NativeStart.main(Native Method)
Was it helpful?

Solution

1) the support-v4 JAR is in the Facebook SDK (or it is easier to find it in the Android SDK in Extra)

2) In the project properties go to Java Build Path, in librairies ---> Add external JARs . Look for the support-v4 Jar. Then go in Order and Export ( still in Java Build Path ) You need to check the support-v4 Jar package, add it. It should work ! :D

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top