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
  • Thanks sharkbait_au I've found the problem, and you were on the right line.

    So the original error in full was
    Failed invoking <symbol>
    UnexpectedTypeException: Expected String, given null
    dataFieldsBuild in C:\Users\chares\OneDrive\Eclipse\Projects\IQShared\IQZZZSportActivity.mc:355


    If you look at the image the line 355 is the one at the top of the post, so I was (or thought I was) looking at the problem line.

    However the actual line causing a problem is 357, not 355. Which from the same image is a mistyped enum where FIELD_HRMAXA should read FIELD_HRMAX (but with enums not being checked by the compiler was missed).

    As FIELD_HRMAXA doesn't exist, I am guessing the pre-compiler is doing something weird to the output/line numbers.

    So in reference to help others, if you get the same error, also check later lines using enums.

    Cheers
    Chris