Array error App<->View in WF : Expected Object/Array/Dictionary/ByteArray, given String

Hi,

i have a little problem, with array.

I have an array in my App, a Global var.

I can use it in App, but it give me an error when using it in my view:

App :

var stockSymbol = ["GRMN", "MSFT"];

function userSettings() {
  StockSymbol[0] = Application.getApp().getProperty("StockCode"); 

  var testStockSymbol = StockSymbol[0];
  Sys.println (" in userSettings --- > testStockSymbol = " + testStockSymbol);
}

give me :  in userSettings --- > testStockSymbol = gnft.pa

It's ok.

But in my view :

function displayStockValue (dc, numCube) {
  var test = StockSymbol[0];

give me UnexpectedTypeException: Expected Object/Array/Dictionary/ByteArray, given String

Any Idea of what i'm missing ?

Thanks !

  • It helps if you show the error you're getting and which line it's on.  A simple way to see what's going on is doing a println of the thing you're getting the error on. (so in this case, StockSymbol.

  • Background: 

    in userSettings --- > testStockSymbol = gnft.pa
     in userSettings --- > testStockSymbol = gnft.pa
    ****background register **** intervalWebRequest =>5

    Error: Unhandled Exception
    Exception: UnexpectedTypeException: Expected Object/Array/Dictionary/ByteArray, given String
    Stack:
      - displayStockValue () at E:\Jean-Marc\Developpement\eclipse\Dev\CubeWatch\source\CubeWatchView.mc:371 0x100027dc

    366    function displayStockValue (dc, numCube) {
    367        getCoordCube (numCube) ;
    368        var price = 0.0;
    369        var stockData ="N-A";
    370       
    371var test = StockSymbol[0];

    The App read usersettings :

        function initialize() {
            AppBase.initialize();
                userSettings();
         }

    	function userSettings() {
    		if (Application.getApp().getProperty("StockCode")) {StockSymbol[0] = Application.getApp().getProperty("StockCode").toString(); }
    
    var testStockSymbol = StockSymbol[0] ;
    Sys.println (" in userSettings --- > testStockSymbol = " + testStockSymbol);		
    ...

  • Wooh ...

    So strange ...

    I had another line, in global var / App :

    var StockSymbol2;

    that  put it for comments to try something ...

    // var StockSymbol2;

    and now it's working.

    Im mémory Usage Stats, i saw thar StockSymbol was a STRING, not an array.

    And now it's an Array !

    I do not understand what happens.

    Maybe a limitation from Garmin specs for naming var's ?

    <edit>I may have put something like StockSymbol="sometext"rather than StockSymbol[0] = "sometext"  because i don't see an other explanation !...</edit>