Android facebook登录按钮崩溃

时间:2015-06-16 22:06:08

标签: android facebook

我完成了Android Facebook SDK 4 in Eclipsehttps://developers.facebook.com/docs/android/getting-started#login_share

的所有步骤

我的活动:

public class MainActivity extends Activity {
    LoginButton loginButton;
    CallbackManager callbackManager;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        FacebookSdk.sdkInitialize(getApplicationContext());
        setContentView(R.layout.activity_main);
        callbackManager = CallbackManager.Factory.create();
        loginButton = (LoginButton) findViewById(R.id.login_button);
        loginButton.setReadPermissions("user_friends");


        // Callback registration
        loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(LoginResult loginResult) {
                // App code
            }

            @Override
            public void onCancel() {
                // App code
            }

            @Override
            public void onError(FacebookException exception) {
                // App code
            }
        });    


        final Button but_nova_hra = (Button) findViewById(R.id.nova_hra);
        but_nova_hra.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent obrazovkaHry = new Intent(getApplicationContext(), HraActivity.class);
                startActivity(obrazovkaHry);
            }
        });

        final Button but_koniec = (Button) findViewById(R.id.konec);
        but_koniec.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
    }
}

应用程序在启动时崩溃

  

找不到从方法com.facebook.internal.Validate.hasFacebookActivity

引用的com.facebook.FacebookActivity

问题出在哪里?

1 个答案:

答案 0 :(得分:1)

该错误的答案是在oncreate constuctor之后的set content视图之前初始化facebook SDK行