Android facebook applicationId 不能为空 [英] Android facebook applicationId cannot be null

查看:34
本文介绍了Android facebook applicationId 不能为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在按照以下教程将我的应用程序与 Facebook 集成.Facebook 教程

我已经按照教程中的所有内容进行操作,但在两种情况下我都遇到 applicationId 不能为空,这真的很令人沮丧.

我的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();片段[SPLASH] = fm.findFragmentById(R.id.splashFragment);片段[选择] = fm.findFragmentById(R.id.selectionFragment);FragmentTransaction 交易 = fm.beginTransaction();for(int i = 0; i 

但是,当我尝试显示活动时,我得到 applicationId 不能为空,LogCat 指向我的行是:uiHelper.onCreate(savedInstanceState);

然后我尝试注释掉该行,并显示活动.但是现在当我点击 LoginButton 时,我得到了同样的错误,但这次我指向了 facebook 的 LoginButton 类中的 applicationId 字段.

我的字符串值和清单中已经有了 Id,如下所示:

我尝试使用代码获取 ID,但没有任何改变.

究竟是什么导致了这一切?

解决方案

TL;DR:您必须strings.xml 中写入应用程序的 ID,然后引用(即 @strings/fb_app_id),因为如果你将它直接(作为值)放入 AndroidManifest.xml 它将不起作用.

您必须在 AndroidManifest.xml 中定义您的 applicationId像这样:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>

标签下

其中 app_idstrings.xml 中的一个字符串.

<小时>

示例:

 <意图过滤器><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></意图过滤器></活动><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"/></应用程序>

** 请注意 <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> 内<应用程序> 标签

-- 在strings.xml 中

1389xxxxxxxx

I've been following the following tutorial to integrate my app with Facebook. Facebook tutorial

I've followed everything on the tutorial, but I've been getting applicationId cannot be null in two cases, and it's really frustrating.

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();
}

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);

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.

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"/>

I tried getting the Id using code, but nothing changed.

What exactly is causing all this?

解决方案

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) into AndroidManifest.xml it won't work.

you must define your applicationId in the AndroidManifest.xml like this:

<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>

under <application android:label="@string/app_name".... tag

where app_id is a string within your strings.xml.


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>

** please note <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/> is within <application> tag

-- and in strings.xml

<string name="app_id">1389xxxxxxxx</string>

这篇关于Android facebook applicationId 不能为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆