0

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:

enter image description here

The values aren't null >o<

pablisco
  • 14,027
  • 4
  • 48
  • 70
  • Which line is the error on? Print out all the arguments you pass it just before you call it. – Kevin Dec 02 '11 at 17:42
  • Where *exactly* is the exception being thrown? – Jon Skeet Dec 02 '11 at 17:43
  • Updated the question with the info requested – pablisco Dec 02 '11 at 17:54
  • Can you please post the entire exception with line numbers? It should be in your logcat output. – Gray Dec 02 '11 at 21:29
  • I think something is leading to null, check the line that throws exception. is it leading to account null or key null? – Mariux Dec 03 '11 at 00:30
  • I don't have access to the project now but the exception is clear from the code where it is thrown (hint: "key is null"). But the thing that puzzles me is that before using the `setUserData` method I was providing the userData with the method `toBundle()` but when retrieving the userData I got null values. – pablisco Dec 07 '11 at 12:39

1 Answers1

1

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.

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.

pablisco
  • 14,027
  • 4
  • 48
  • 70