2

我正在使用社交身份验证库在 android 应用程序中与社交媒体共享和登录。

我已成功登录并使用 facebook 授权。但是当我尝试注销时应用程序因空指针异常而崩溃

adapter.signOut(getActivity(), Provider.FACEBOOK.toString());

出现以下错误:

05-09 10:24:23.010: E/AndroidRuntime(19998): java.lang.NullPointerException
05-09 10:24:23.010: E/AndroidRuntime(19998): at org.brickred.socialauth.android.SocialAuthAdapter.signOut(SocialAuthAdapter.java:797)

我正在使用最新版本。socialauth-4.4.jar 和 socialauth-android-3.2.jar

4

4 回答 4

0
In signOut function put these lines,

if (providerName != null) {
            if (socialAuthManager == null) {
                socialAuthManager = new SocialAuthManager();
                try {
                    loadConfig(ctx);
                } catch (Exception e) {
                    Log.d(" SocialAuthAdapter ", "Could not load configuration");
                }
            }

before 

if (socialAuthManager.getConnectedProvidersIds().contains(providerName)) socialAuthManager.disconnectProvider(providerName);
于 2015-04-15T14:22:48.160 回答
0

我有一个类似的问题,这个解决方案对我有用: https ://code.google.com/p/socialauth-android/issues/detail?id=108#c16

基本上注销功能有一个bug,必须先登录再注销,否则可能会出现NPE。上面的解决方案是在必要时创建一个新的 SocialAuthManager。

我建议将该源代码作为 java 模块导入,而不是使用 jar 文件,这样您就可以自己修复一些问题,例如更改对话框标题文本等...

于 2015-01-04T16:08:19.257 回答
0

请确保从活动中调用。从这样的活动调用方法后,片段中的 Getactivity() 不起作用 adapter.signOut(this, Provider.FACEBOOK);

于 2015-01-02T13:57:18.027 回答
0

这已经解决了我现在的问题,如果应用程序范围的适配器为空,则在您想要注销的类中实例化一个新适配器

//My Activity
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);

    //Get the currently available adapter
    myApp = (MyApplication) getApplication();
    adapter = myApp.getSocialAuthAdapter();

    //Adapter initialization if null
    if (adapter==null){
        adapter = new SocialAuthAdapter(new ResponseListener());
    }
}

//ResponseListener Class
    public final class ResponseListener implements DialogListener {

    @Override
    public void onComplete(Bundle values) {

        String providerName = values.getString(SocialAuthAdapter.PROVIDER);

        // Set a application wide reference to the social adapter here
        myApp = (MyApplication) getApplication();
        myApp.setSocialAuthAdapter(adapter);                         
    }

    @Override
    public void onError(SocialAuthError error) {
        Log.d("Custom-UI", "Error");
        error.printStackTrace();
    }

    @Override
    public void onCancel() {
        Log.d("Custom-UI", "Cancelled");
    }

    @Override
    public void onBack() {
        Log.d("Custom-UI", "Dialog Closed by pressing Back Key");

    }
}


//Code for application class

public class MyApplication extends Application {

// SocialAuth Component
private SocialAuthAdapter socialAuthAdpater;

public SocialAuthAdapter getSocialAuthAdapter() {
        return socialAuthAdpater;
}

public void setSocialAuthAdapter(SocialAuthAdapter socialAuthAdapter) {
        this.socialAuthAdpater = socialAuthAdapter;
}
于 2015-05-01T17:42:47.113 回答