私は自分のアプリを Facebook と統合するために、次のチュートリアルに従っています。Facebookチュートリアル
チュートリアルのすべてに従いましたが、applicationId cannot be null
2 つのケースが発生しており、非常にイライラしています。
私の場合FacebookActivity
onCreate
は次のようになります。これはチュートリアルとまったく同じです。
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
uiHelper = new UiLifecycleHelper(this, callback);
uiHelper.onCreate(savedInstanceState);
setContentView(R.layout.main_fb);
FragmentManager fm = getSupportFragmentManager();
fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
FragmentTransaction transaction = fm.beginTransaction();
for(int i = 0; i < fragments.length; i++)
{
transaction.hide(fragments[i]);
}
transaction.commit();
}
しかし、アクティビティを表示しようとするとapplicationId cannot be null
、LogCat が示す行は次のようになります。uiHelper.onCreate(savedInstanceState);
そこで、その行をコメントアウトしてみると、アクティビティが表示されます。ただし、をクリックすると、LoginButton
同じエラーが発生しますが、今回は が Facebook の LoginButton クラスの applicationId フィールドを指しています。
文字列値とマニフェストにはすでに ID が含まれています。
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/APP_ID"/>
コードを使用して ID を取得しようとしましたが、何も変わりませんでした。
一体何がこのすべての原因なのでしょうか?
ベストアンサー1
TL;DR: あなた持っているアプリケーションの ID を に書き込んで
strings.xml
から参照します (つまり@strings/fb_app_id
)。 に直接 (値として) 入力するとAndroidManifest.xml
機能しないためです。
applicationId
を次のように定義する必要がありますAndroidManifest.xml
。
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
<application android:label="@string/app_name"....
タグの下
app_id
は 内の文字列ですstrings.xml
。
サンプル:
<application android:label="@string/app_name"
android:icon="@drawable/icon"
android:theme="@android:style/Theme.NoTitleBar"
>
<activity android:name=".HelloFacebookSampleActivity"
android:label="@string/app_name"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name="com.facebook.LoginActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
</application>
**タグ<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>
内に注意してください<application>
-- そしてstrings.xml
<string name="app_id">1389xxxxxxxx</string>