简体   繁体   English

Android Studio:Facebook登录

[英]Android Studio: Facebook Log in

I am trying to make a really basic Facebook login program for Android studio. 我正在尝试为Android Studio开发一个非常基本的Facebook登录程序。 I have followed all of the steps, exactly as described in at least 4 tutorials, but the result remains the same. 我遵循了所有步骤,至少与至少4个教程中所述完全相同,但是结果仍然相同。 When I open the app it crashes. 当我打开应用程序时,它崩溃了。 So here is my code: 所以这是我的代码:

private FacebookCallback<LoginResult> mCallBack = new  FacebookCallback<LoginResult>(){
    @Override
    public void onSuccess(LoginResult loginResult) {
        AccessToken accessToken = loginResult.getAccessToken();
        Profile profile = Profile.getCurrentProfile();
        if(profile!=null){

            textlogin.setText("Hello "+profile.getFirstName());
        }
    }

    @Override
    public void onCancel() {
        // App code
    }

    @Override
    public void onError(FacebookException exception) {
        // App code
    }

};




  @Override
    public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
        FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
        callbackManager=CallbackManager.Factory.create();

    }
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    LoginButton loginButton = (LoginButton)view.findViewById(R.id.login_button);
    textlogin = (TextView)view.findViewById(R.id.textView);
    loginButton.setReadPermissions("user_friends");
    loginButton.setFragment(this);
  loginButton.registerCallback(callbackManager, mCallBack);
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    return inflater.inflate(R.layout.fragment_main, container, false);

}

and here is the error log (it really is that short): 这是错误日志(实际上就是这么短):

java.lang.NullPointerException
        at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:911)
        at com.facebook.internal.Utility.queryAppSettings(Utility.java:802)
        at com.facebook.login.widget.LoginButton$1.run(LoginButton.java:509)
        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:841)

Found error. 发现错误。 Misplaced the <Metadata> . 错误放置了<Metadata> All working now! 现在都在工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM