AccountManager IllegalArgumentException: 键为空 [英] AccountManager IllegalArgumentException: key is null

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

问题描述

好的,我在不应该的地方收到了 IllegalArgumentException.

Ok, I'm getting an IllegalArgumentException at a point where it shouldn't.

我有一个使用 AccountManager 保存的 Account 自定义扩展:

I have a custom extension of Account that is saved using the AccountManager:

// Method inside a custom extension of Account
public boolean save(AccountManager manager) {
    removeAll(manager);
    boolean result = manager.addAccountExplicitly(this, null, toBundle());
    manager.setUserData(this, KEY_1, value1);
    manager.setUserData(this, KEY_2, value2);
    manager.setUserData(this, KEY_3, value3);
    return result;
}

键是常量字符串值,但应用程序仍然抛出:

The keys are constant String values but app still throws:

java.lang.IllegalArgumentException: key is null

我不得不说我只是以这种方式附加用户数据,因为使用:

I have to say that I'm only attaching the user data in this fashion because using:

 manager.addAccountExplicitly(this, null, toBundle());

似乎没有附加值.键是否需要特殊的名称模式?

didn't seem to attach the values. Do the keys require a special name pattern?

有人遇到过这个问题吗?

Anybody had this problem before?

更新:

它被抛出到 manager.setUserData() 里面,看起来像这样(Android 代码):

It gets thrown inside the manager.setUserData() which looks like this (Android code):

public void setUserData(final Account account, final String key, final String value) {
    if (account == null) throw new IllegalArgumentException("account is null");
    if (key == null) throw new IllegalArgumentException("key is null");
    try {
        mService.setUserData(account, key, value);
    } catch (RemoteException e) {
        // won't ever happen
        throw new RuntimeException(e);
    }
}

当我用 Eclipse走进"这个方法时,我在调试角度得到了这个:

When I "walk" into this method with eclipse I get this in the debug perspective:

值不为空 >o<

推荐答案

好的,经过进一步研究 的 AccountManager 我没有找到让它像我尝试的那样工作的方法,但我找到了一个解决方案.

Ok, after further research into 's AccountManager I did not find a way to make it work like I was trying but I found a solution.

我没有将详细信息保存为用户数据包,而是使用密钥作为 authTokenType 将它们保存为 authToken 值,如下所示:

Instead of saving the details as an user data bundle I save them as authToken values using the key as the authTokenType like this:

public boolean save(AccountManager manager) {
    removeAll(manager);
    boolean result = manager.addAccountExplicitly(this, null, toBundle());
    manager.setAuthToken(this, KEY_1, value1);
    manager.setAuthToken(this, KEY_2, value2);
    manager.setAuthToken(this, KEY_3, value3);
    return result;
}

然后像这样检索值:

value1 = manager.peekAuthToken(account, KEY_1);

我仍然不确定这是否是为 Account 存储数据的方式,但这是我迄今为止唯一成功的方法.

I'm still not sure if this is the way to store data for an Account but it's the only one I've managed to make work so far.

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

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