Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager facebook android app

I know this question has been asked and I've tried using many other posts to help me through this but none have worked. I am working through this link to install a Facebook login onto an Android app: https://developers.facebook.com/docs/android/getting-started. I have imported the Facebook SDK and it works for the sample apps so I know thats ok. I DO NOT have any JARs in my libs folder. In properties > Android libraries I have added appcompat_v7 and FacebookSDK. In Built Path > Order and Export I have Android Dependencies and Android Private Libraries both checked.

The error

java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager

happens on this line of code:

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

Any ideas on why this is happening? I have been messing around with my properties all day and can't get it working. The code is right off of the FB developer site so I'm sure its fine. Thanks.

07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)
07-23 16:19:18.506: I/dalvikvm(22318): Could not find method android.support.v4.content.LocalBroadcastManager.getInstance, referenced from method com.facebook.Session.postActiveSessionAction
07-23 16:19:18.506: W/dalvikvm(22318): VFY: unable to resolve static method 222: Landroid/support/v4/content/LocalBroadcastManager;.getInstance (Landroid/content/Context;)Landroid/support/v4/content/LocalBroadcastManager;
07-23 16:19:18.506: D/dalvikvm(22318): VFY: replacing opcode 0x71 at 0x0009
07-23 16:19:18.545: D/AndroidRuntime(22318): Shutting down VM
07-23 16:19:18.545: W/dalvikvm(22318): threadid=1: thread exiting with uncaught exception (group=0x419707c0)
07-23 16:19:18.545: E/AndroidRuntime(22318): FATAL EXCEPTION: main
07-23 16:19:18.545: E/AndroidRuntime(22318): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
07-23 16:19:18.545: E/AndroidRuntime(22318):    at com.facebook.Session.postActiveSessionAction(Session.java:1567)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at com.facebook.Session.setActiveSession(Session.java:974)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at com.facebook.Session.openActiveSession(Session.java:1129)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at com.facebook.Session.openActiveSession(Session.java:1014)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at com.example.testfb3.MainActivity.onCreate(MainActivity.java:18)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.Activity.performCreate(Activity.java:5133)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.os.Looper.loop(Looper.java:137)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at android.app.ActivityThread.main(ActivityThread.java:5289)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at java.lang.reflect.Method.invokeNative(Native Method)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at java.lang.reflect.Method.invoke(Method.java:525)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
07-23 16:19:18.545: E/AndroidRuntime(22318):    at dalvik.system.NativeStart.main(Native Method)

Full Activity:

public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// start Facebook Login
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.newMeRequest(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.welcome);
            welcome.setText("Hello " + user.getName() + "!");
          }
        }
      }).executeAsync();
    }
  }
});
}

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

}

EDIT

Just to give you guys a visual of what my settings look like:

side

side

side

like image 974
user1282637 Avatar asked Jul 23 '14 20:07

user1282637


1 Answers

As my experience, this error happens from build settings.

I suggest to do as follows.

Click button "Add jars..."

Select "android-support-v4.jar" from

Select tab "Order and Export" and check "android-support-v4.jar".

Clean the project and build.

After run project, then app will execute.

Good luck

--Andrey Alexander--

like image 143
Andrey. Alexander Avatar answered Oct 25 '22 22:10

Andrey. Alexander