0

我正在尝试将 facebook 与 android 集成。遵循https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/中的步骤

我的应用程序安装在模拟器上,但是当我尝试打开应用程序时,我收到一条错误消息“不幸的是 app_name 已停止工作”

代码中没有错误,但我收到如下运行时错误

08-13 17:50:32.655: W/dalvikvm(1553): VFY: unable to find class referenced in signature         (Landroid/support/v4/app/Fragment;)

08-13 17:50:32.655: W/dalvikvm(1553): VFY: unable to find class referenced in signature (Landroid/support/v4/app/Fragment;)    
08-13 17:50:32.666: I/dalvikvm(1553): Could not find method android.support.v4.content.LocalBroadcastManager.getInstance, referenced from method com.facebook.Session.postActiveSessionAction    
08-13 17:50:32.666: W/dalvikvm(1553): VFY: unable to resolve static method 187: Landroid/support/v4/content/LocalBroadcastManager;.getInstance (Landroid/content/Context;)Landroid/support/v4/content/LocalBroadcastManager;       
08-13 17:50:32.666: D/dalvikvm(1553): VFY: replacing opcode 0x71 at 0x0009        
08-13 17:50:32.867: D/AndroidRuntime(1553): Shutting down VM        
08-13 17:50:32.867: W/dalvikvm(1553): threadid=1: thread exiting with uncaught exception (group=0x40a13300)        
08-13 17:50:32.876: E/AndroidRuntime(1553): FATAL EXCEPTION: main        
08-13 17:50:32.876: E/AndroidRuntime(1553): java.lang.NoClassDefFoundError:         android.support.v4.content.LocalBroadcastManager    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.facebook.Session.postActiveSessionAction(Session.java:1215)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.facebook.Session.setActiveSession(Session.java:765)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.facebook.Session.openActiveSession(Session.java:865)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.facebook.Session.openActiveSession(Session.java:805)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.example.projectwin.MainActivity.onCreate(MainActivity.java:19)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.Activity.performCreate(Activity.java:5008)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.ActivityThread.access$600(ActivityThread.java:130)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.os.Handler.dispatchMessage(Handler.java:99)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.os.Looper.loop(Looper.java:137)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at android.app.ActivityThread.main(ActivityThread.java:4745)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at java.lang.reflect.Method.invokeNative(Native Method)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at java.lang.reflect.Method.invoke(Method.java:511)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)    
08-13 17:50:32.876: E/AndroidRuntime(1553):     at dalvik.system.NativeStart.main(Native Method)    

MainActivity.java 是

package com.example.projectwin;    


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.model.*;

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.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.welcome);
                welcome.setText("Hello " + user.getName() + "!");
              }
            }
          });
        }
      }
    });
  }

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

}

等待这个问题的解决方案...

4

2 回答 2

2

从日志中,您的构建路径中似乎没有设置 Android 支持库

于 2013-08-14T01:13:29.430 回答
0
android.support.v4.content.LocalBroadcastManager

这个方法可以找!那是因为缺少android支持库!

导入该库并添加到构建路径右键单击它,然后单击Add To Build Path

于 2013-08-14T01:13:39.547 回答