LoginButton facebook android NullPoiunterExecptioi [英] LoginButton facebook android NullPoiunterExecptioi

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

问题描述

我想将登录按钮添加到我的应用程序,所以我按照facebook的指导。我创建了我的应用程序项目,我添加一个android项目,告诉包的名称和主要活动的路径和从默认密钥库生成的哈希码(我用它告诉我的android调试密钥库,因为该应用程序是只有在alfa测试,所以为了个人发展的原因,我更喜欢使用从android studio生成的调试版本)。然后我将字符串资源放在应用程序ID中,并在标签应用程序中使用Facebook应用程序ID作为指导说明的元数据。然后我设置环境:

I wanted to add the login button to my app and so i followed the guide of facebook about that. I created my app project i add an android project telling the name of the package and the path of the mainactivity and the hash code generated from the default keystore (i used as they tell to me the android debug keystore because for the moment the app is only in alfa test and so for personal developing reason i prefer to use the debug version generated from android studio). Then i put in string resource the app id and in the tag application the meta-data with facebook app id as the guide says. Then i set the enviroment as well:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());

    /**
     *
     *
     * part dedicated to facebook button
     */
    manager=CallbackManager.Factory.create();

    setContentView(R.layout.activity_main);
    loginButton=(LoginButton)findViewById(R.id.facebook_logi);
    loginButton.setReadPermissions("email");

    loginButton.registerCallback(manager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.i("Facebook","Login success");
        }

        @Override
        public void onCancel() {
            Log.i("Facebook","Login cencelled");
        }

        @Override
        public void onError(FacebookException error) {
            Log.i("Facebook","Login error "+error.getMessage());

        }
    });

    /**
     *
     *
     * end of facebook part
     */

当我试图运行它时,VM会产生这种异常

and when i tried to run it the VM generate this exception

 java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
                                                                                      at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:746)
                                                                                      at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:774)
                                                                                      at com.facebook.internal.FetchedAppSettingsManager.queryAppSettings(FetchedAppSettingsManager.java:147)
                                                                                      at com.facebook.login.widget.LoginButton$1.run(LoginButton.java:499)
                                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                                      at java.lang.Thread.run(Thread.java:818)

任何人都可以帮助我,因为我在这里搜索类似的问题,但我只找到人们把脸谱数据与facebook_app_id外面的应用程序标签。感谢所有的确。

can anyone help me becouse i searched here for similar questions but i only found ones where people putted the meda-data with facebook_app_id outsidethe application tag..Thanks to all indeed.

推荐答案

您的元标记应在Manifest中的应用程序标签内:

your meta tag should be inside application tag in Manifest:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

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

</application>

另外,如果你使用自定义登录按钮;

Also if u use custom login button;

将其添加到您的布局中:

add this to your layout:

 <com.facebook.login.widget.LoginButton
        android:id="@+id/login_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone" />

在您的活动中

 loginButton=(LoginButton)findViewById(R.id.login_button);
loginButton.setReadPermissions("email");

loginButton.registerCallback(manager, new FacebookCallback<LoginResult>() {
    @Override
    public void onSuccess(LoginResult loginResult) {
        Log.i("Facebook","Login success");
    }

    @Override
    public void onCancel() {
        Log.i("Facebook","Login cencelled");
    }

    @Override
    public void onError(FacebookException error) {
        Log.i("Facebook","Login error "+error.getMessage());

    }
});

现在只需调用Facebook 登录按钮当用户点击你自定义的按钮

now just invoke facebook login button when user clicked on your custom button

public void onClick(View v) {
    if (v == facebook_logi) {
        loginButton.performClick();
    }
 }

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

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