AccountManager IllegalArgumentException:键为空
好吧,我在不应该的地方收到了 IllegalArgumentException
。
我有一个使用 AccountManager 保存的 Account
自定义扩展:
// 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;
}
键是常量字符串值,但应用程序仍然抛出:
java.lang.IllegalArgumentException: key is null
我不得不说,我只是以这种方式附加用户数据,因为使用:
manager.addAccountExplicitly(this, null, toBundle());
似乎没有附加值。按键是否需要特殊的名称模式?
以前有人遇到过这个问题吗?
更新:
它被抛出到 manager.setUserData()
中,看起来像这样(Android 代码):
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 “走进”这个方法时,我在调试视角:
值不为 null >o<
Ok, I'm getting an IllegalArgumentException
at a point where it shouldn't.
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?
Update:
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);
}
}
When I "walk" into this method with eclipse I get this in the debug perspective:
The values aren't null >o<
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,经过进一步研究
android 的
AccountManager
I没有找到让它像这样工作的方法我正在尝试,但我找到了解决方案。我没有将详细信息保存为用户数据包,而是使用密钥作为
authTokenType
将它们保存为authToken
值,如下所示:然后检索如下值
:仍然不确定这是否是存储帐户数据的方式,但这是迄今为止我唯一成功的方法。
Ok, after further research into
android's
AccountManager
I did not find a way to make it work like I was trying but I found a solution.Instead of saving the details as an user data bundle I save them as
authToken
values using the key as theauthTokenType
like this:And then retrieving the values like this:
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.