Android facebook applicationId不能为空 [英] Android facebook applicationId cannot be null
问题描述
我一直在遵循以下教程将我的应用程序与Facebook集成。
Facebook教程
I've been following the following tutorial to integrate my app with Facebook. Facebook tutorial
我已经遵循了教程中的所有内容,但是在两种情况下,我已经得到 applicationId不能为空
,这真是令人沮丧。
I've followed everything on the tutorial, but I've been getting applicationId cannot be null
in two cases, and it's really frustrating.
我的 FacebookActivity
onCreate
具有以下内容,与教程完全一样:
My FacebookActivity
onCreate
has the following, which is exactly the same as the tutorial:
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不能为null
,而LogCat行指向的是: uiHelper.onCreate(savedInstanceState);
However when I try to display the activity I get applicationId cannot be null
, and the line LogCat points me to is: uiHelper.onCreate(savedInstanceState);
所以我尝试注释掉该行,并显示活动。不过现在,当我点击 LoginButton
时,我收到相同的错误,但这次是将我指向来自Facebook的LoginButton类中的applicationId字段。
So then I tried commenting out that line, and the activity is displayed. However now when I click on the LoginButton
, I get the same error but this time is points me to the applicationId field in the LoginButton class from facebook.
我已经在我的字符串值和我的清单中有这样的id:
I already have the Id in my string values and my manifest like this:
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/APP_ID"/>
我尝试使用代码获取Id,但没有改变。
I tried getting the Id using code, but nothing changed.
究竟是什么导致所有这些?
What exactly is causing all this?
推荐答案
TL; DR:您有将您的应用程序的ID写入您的
strings.xml
中,然后引用(即@ strings / fb_app_id
),因为如果将它直接(作为值)放在AndroidManifest.xml
中,它将无法正常工作。 >
TL;DR: you have to write your application's ID in your
strings.xml
and then reference (i.e.@strings/fb_app_id
), because if you put it directly (as value) intoAndroidManifest.xml
it won't work.
您必须在 AndroidManifest.xml中定义
applicationId
/ code>
这样:
you must define your applicationId
in the AndroidManifest.xml
like this:
< meta-data android:name =com.facebook.sdk。 ApplicationIdandroid:value =@ string / app_id/>
在< application android:label =@ string / app_name....
标签
其中 app_id
$ strings.xml
中的一个字符串。
where app_id
is a string within your strings.xml
.
示例: / p>
sample:
<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.ApplicationIdandroid:value =@ string / app_id/>
在< application>
标签
- 和strings.xml
-- and in strings.xml
<string name="app_id">1389xxxxxxxx</string>
这篇关于Android facebook applicationId不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!