2016-08-04 5 views
1

Facebook SDKを実装するときにこのエラーが発生しましたが、tried - many of the-solutionsです。これは私が持っているものです。SDKは初期化されていませんので、まずFacebookSdk.sdkInitialize()を呼び出してください。

@Override 
    protected void onCreate(@Nullable Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     FacebookSdk.sdkInitialize(getApplicationContext()); 
     callbackManager = CallbackManager.Factory.create(); 
     setContentView(R.layout.activity_name_layout); 

LoginButton loginButton = (LoginButton)findViewById(R.id.fb_login_button); 
     loginButton.setReadPermissions(Arrays.asList("public_profile", "email")); 
     loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() { 
      @Override 
      public void onSuccess(LoginResult loginResult) { 

      } 

      @Override 
      public void onCancel() { 

      } 

      @Override 
      public void onError(FacebookException error) { 

      } 
     }); 

    @Override 
     protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
      super.onActivityResult(requestCode, resultCode, data); 
      callbackManager.onActivityResult(requestCode, resultCode, data); 
     } 

Graddle:

compile 'com.facebook.android:facebook-android-sdk:4.8.0' 

マニフェスト:

<activity android:name="com.facebook.FacebookActivity" 
      android:configChanges= 
       "keyboard|keyboardHidden|screenLayout|screenSize|orientation" 
      android:theme="@android:style/Theme.Translucent.NoTitleBar" 
      android:label="@string/app_name" /> 

レイアウト]ボタン:

<LinearLayout 

    xmlns:facebook="http://schemas.android.com/apk/res-auto" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:background="@color/colorPrimaryDark" 
    android:padding="10dp" 
    android:layout_height="match_parent"> 

    <com.facebook.login.widget.LoginButton 
     android:layout_marginTop="10dp" 
     android:id="@+id/fb_login_button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 

     ></com.facebook.login.widget.LoginButton> 
</LinearLayout> 

誰かがイムは間違っているものを私に指摘することができます?

+2

クリーンと再構築します – kgandroid

答えて

0

ドキュメントは、あなたが今Applicationクラスでそれを設定している:

public class MyApplication extends Application { 
    @Override 
    public void onCreate() { 
     super.onCreate(); 
     // Initialize the SDK before executing any other operations, 
     FacebookSdk.sdkInitialize(getApplicationContext()); 
     AppEventsLogger.activateApp(this); 
    } 
} 

https://developers.facebook.com/docs/android/getting-started/

関連する問題