Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Properties.getInt on Android error?

I'm getting an error on Android only when trying to use properties.getInt().

On the first page i set a property, which is getting an id from a database query result set:

    //Set a property so that we can refer back to it
    Ti.App.Properties.setInt("category",e.rowData.id);

Then on the following page i retrieve the property:

//Get property value we set earlier
var categoryId = Titanium.App.Properties.getInt("category");

In the emulator & on a real Android device I get:

"Wrapped java.lang.IllegalArgumentException:argument type mismatch"

I'm guessing that this should work fine. However looking at the KitchenSkin code I see that they are retrieving all of the setters using getString even when the property is set using setInt()?

Is this a known bug? Is the answer to get all set properties as Strings when I really need an int?

UPDATE I am now sure this is a bug. getString works fine getInt crashes the app in Android.

— asked June 14th 2010 by James Whittaker
  • android
  • getint
  • properties
  • properties.getint
  • setint
3 Comments
  • What is the actually value being sent to setInt?

    — commented June 15th 2010 by Don Thorp
  • Don, I get this same error when explicitly sending setInt an int:

    Titanium.App.Properties.setInt('score', 0);

    getInt produces the error, getString does not

    Android emulator 1.6, Titanium Mobile 1.3, Ubuntu 10.04

    — commented June 26th 2010 by Jeremy Raines
  • Did you figure out a solution for this? I have the exact same error on Android.

    — commented July 1st 2010 by Leigh Kayley

1 Answer

  • Same issue with getBool(), 4 weeks old anyone have any tips?

    Edit-> Found this in the sample:

    Titanium.API.info('String: '+ Titanium.App.Properties.getString('String'));
    Titanium.API.info('Int: '+ Titanium.App.Properties.getString('Int'));
    Titanium.API.info('Bool: '+ Titanium.App.Properties.getString('Bool'));
    Titanium.API.info('Double: '+ Titanium.App.Properties.getString('Double'));

    They're using getString for everything.

    The documentation shows:

    http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.App.Properties.getBool-method.html

    http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.App.Properties.getInt-method.html

    So this is a bug in my opinion.

    Confirmed workaround, set the default value which is used if the setting is not found:

    if (Ti.App.Properties.getBool('geo.testmode',false) === true) { }

    — answered July 9th 2010 by Justin Carlson
    permalink
    6 Comments
    • Well, this isn't really an answer is it… can't delete it though.

      — commented July 9th 2010 by Justin Carlson
    • No luck so far (although not tried on latest 1.3.3). All the KitchenSkin apps use getString. I'm using that for ints, which is not great. Is there a bug number for this or do we need to create one?

      — commented July 9th 2010 by James Whittaker
    • Edited answer, looks like we're to use getString and pass the expected type.

      — commented July 9th 2010 by Justin Carlson
    • Nevermind, they just named their vars the same as their types… sigh

      — commented July 9th 2010 by Justin Carlson
    • There is a ticket for this. Ticket 1035 you can work around it by adding a default parameter.

      — commented July 9th 2010 by Don Thorp
    • Thanks, I was just looking for the bug list!

      — commented July 9th 2010 by Justin Carlson
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.