抛出:IllegalArgumentException的AccountManager:关键是空 [英] AccountManager IllegalArgumentException: key is null

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

问题描述

好吧,我发现了一个抛出:IllegalArgumentException 在一个点,它不应该。

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

我有一个自定义扩展帐户正在使用的AccountManager保存:

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()它看起来像这样(的Andr​​oid code):

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<

The values aren't null >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.

而不是节约的细节为用户的数据包的我将它们保存为的authToken 使用密钥作为 authTokenType 是这样的:

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;
}

,然后检索这样的值:

And then retrieving the values like this:

value1 = manager.peekAuthToken(account, KEY_1);

我仍然不知道这是存储为帐户数据的方式,但它是唯一一个我已经成功地使工作至今。

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.

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

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