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

时间:2014-07-23 20:32:25

标签: java android facebook properties

我知道这个问题已被提出,我已尝试使用许多其他帖子来帮助我完成此操作,但没有一个有效。我正在通过此链接安装Facebook登录到Android应用程序:https://developers.facebook.com/docs/android/getting-started。我已经导入了Facebook SDK,它适用于示例应用程序,所以我知道没关系。我的libs文件夹中没有任何JAR。在属性> Android库我添加了appcompat_v7和FacebookSDK。在Built Path中>订单和导出我检查了Android依赖项和Android私有库。

错误

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

发生在这行代码上:

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

有关为何发生这种情况的任何想法?我一整天都在弄乱我的房产而且无法让它运转起来。代码就在FB开发者网站上,所以我确定没问题。感谢。

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)

完整活动:

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);
}

}

修改

只是为了让你们了解我的设置是什么样的:

side

side

side

1 个答案:

答案 0 :(得分:13)

根据我的经验,此错误发生在构建设置中。

我建议如下。

点击按钮"添加罐子......"

选择" android-support-v4.jar"来自

选择标签"订购和导出"并检查" android-support-v4.jar"。

清理项目并构建。

运行项目后,应用程序将执行。

祝你好运

- 安德烈亚历山大 -