Weird Problem - Just for Discussion

All,

I know this can't be solved by the forum, but I wanted to just post it, as I can't find a solution without removing the code. It also could trigger somebody else with the same or similar problem.

My original line is below, and this fails with 'Failed invoking <symbol> UnexpectedTypeException: Expected String, given null'
values[valueIndex+1] = [heartrateToString(info.currentHeartRate)];


Now, I know, there's a few things that can go wrong here, so after some messing around, I changed to the code below, but still get the same error.
values[valueIndex+1] = null;


Again, the variables may be invalid, or the index too high, so using println, here's what I get:
Sys.println(valueIndex+1); returns 5
Sys.println(values.size()); returns 6
Sys.println(values[valueIndex+1]); returns null

So basically the index is in range and value is currently null, but when I try to set to any value (including null) I get the same error.

Even more weird, the line before the error is similar, and works perfectly.
values[valueIndex] = [heartrateToString(info.averageHeartRate)];


Basically, I am lost! Discuss.

Cheers
Chris
  • I'm guessing this in in a data field and in compute().

    Are you doing any check for info.currentHeartRate being null? It will be null before the recording has started.
  • Thanks Jim for the response.

    I'm guessing this in in a data field and in compute().

    It's within a onUpdate on a App.

    Are you doing any check for info.currentHeartRate being null? It will be null before the recording has started.

    That was my initial reaction. The purpose of the function heartrateToString is to check for null on the property (currentHeartRate) and format an output, as well as formatting a real value. I also checked for info being null.

    Therefore that's why I took it back to barebones and just tried assigning the most basic value null, which also fails. So this fails too values[valueIndex+1] = null;

    Cheers
    Chris
  • Which exact line of code are you getting the error on?
  • The initial line was:
    values[valueIndex+1] = [heartrateToString(info.currentHeartRate)];


    But this also fails
    values[valueIndex+1] = null;


    This:
    Sys.println(values[valueIndex+1]);


    Returns:
    null


    So, these two lines:
    Sys.println(values[valueIndex+1]);
    values[valueIndex+1] = null;


    Print these lines to the Console
    null
    Failed invoking <symbol>
    UnexpectedTypeException: Expected String, given null


    Cheers
    Chris
  • Why are you doing:

    values[valueIndex+1] = [heartrateToString(info.currentHeartRate)];

    instead of:
    values[valueIndex+1] = heartrateToString(info.currentHeartRate);

    ?

    It seems you want to put a string in the array. Yet you also put null into the array (not an empty string but a null)
  • This array is passed to my UI render class. If the Array has a single length, the value is rendered on the UI. If it has two values, the second indicates the colour to render as.

    So it can be populated as ["157"] to render 157 in the default colour, otherwise elsewhere it could be ["157", Gfx.COLOR_RED] to render 157 in Red. Other parts of the code are executing this.

    The render class then checks the size, and if 2 in length, calls setColor first with the second parameter.

    I know this is not impacting this line, as it fails whatever is on the right-hand side of the equals, as I tried a range of values to see if that was the fault.
  • Former Member
    Former Member
    Do eithervalues[valueIndex] = [heartrateToString(info.currentHeartRate)];orvalues[valueIndex+1] = [""];work?
  • It seems you want to put a string in the array. Yet you also put null into the array (not an empty string but a null)


    Maybe I am not being clear. I don't want to put null in the array, I just wanted to show the right-hand side had no impact on the error, as no matter what it always failed.
  • Do eithervalues[valueIndex] = [heartrateToString(info.currentHeartrate)];orvalues[valueIndex+1] = [""];work?


    No, sorry just tried, and the first works, and the second fails.
  • Former Member
    Former Member
    Assuming you are using eclipse.....

    I have had a couple of strange eclipse errors in the past. Pretty sure it wasn't me :). It was like the file was cached or something, and updates weren't being read. I would suggest copy/pasting into an external file. Delete original file. Restart eclipse. Recreate file.