未找到类定义错误

未找到类定义错误

本文介绍了解析和Facebook集成(未找到类定义错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用Parse BaaS的Android应用,我希望使用户能够使用其Facebook帐户登录.我正在使用Android Studio.我导入了Facebook sdk,Parse和ParseFacebookUtils jar文件.我有以下活动代码

I am developing an Android app that uses Parse BaaS and I want to enable users to login using their facebook account. I am using Android Studio. I imported facebook sdk and Parse and ParseFacebookUtils jar files.I have the following activity code

private void initUI() {
    this.loginButton = (Button) findViewById(R.id.main_login_button);
    this.loginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            loginWithFacebook();
        }
    });
}

private void loginWithFacebook() {
    ParseFacebookUtils.logIn(this, REQUEST_LOGIN, new LogInCallback() {
        @Override
        public void done(ParseUser parseUser, ParseException e) {
            logToDisplay("User logged in " + parseUser.getUsername());

        }
    });
}

loginWithFacebook方法被调用.不幸的是,它引发以下异常:

The loginWithFacebook method is called. Unfortunately, it throws the following exception:

java.lang.NoClassDefFoundError: com.facebook.Session$Builder

我在做什么错了?

预先感谢;)

推荐答案

使用Parse Android 1.9,我们必须包含ParseFacebookUtils4.jar

With Parse Android 1.9, we have to include ParseFacebookUtils4.jar

此外,在进行12小时的研究后,文档中给出的示例无效.这是我为Parse 1.9和Facebook 4.0 SDK提供的有效解决方案

Also the example given in the documentation is not valid after doing a research for 12 hours. Here is the working solution i have for Parse 1.9 and Facebook 4.0 SDK

 Button b = (Button)findViewById(R.id.login_button);
    ParseFacebookUtils.initialize(this);
    //showHashKey(this);
    b.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ParseFacebookUtils.logInWithReadPermissionsInBackground(YOUR_ACTIVITY.this, YOUR_PERMISION_COLLECTION, new LogInCallback() {
                @Override
                public void done(ParseUser user, ParseException err) {
                    if (user == null) {
                        Log.d("MyApp", "Uh oh. The user cancelled the Facebook login.");
                    } else if (user.isNew()) {
                        Log.d("MyApp", "User signed up and logged in through Facebook!");
                    } else {
                        Log.d("MyApp", "User logged in through Facebook!");
                    }
                }
            });
        }
    });

ParseFacebookUtils.logIn在ParseFacebookUtils4中已弃用.另外,onActivityResult上还有一个不推荐使用的函数ParseFacebookUtils.finishAuthentication.现在应该像下面一样

ParseFacebookUtils.logIn is deprecated in ParseFacebookUtils4. Also there is another deprecated function ParseFacebookUtils.finishAuthentication on onActivityResult. It should be now like below

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}

这篇关于解析和Facebook集成(未找到类定义错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:33