connect Iq 2... ->4 elementary error

Hello! In 2021, I made a watch face, then it was the era of "", now there is a different development environment, and all the functions work differently. I am trying to transfer my watch face to the new environment, but so far it is not working out very well. Swears at elementary things that seem to work in the help. For example:

using Toybox.Time;
class WatchWeatherView   extends Ui.WatchFace {
   public function onUpdate(dc)
    {
      var now             = Time.now();

    }

Ang get the error:


Error: Unhandled Exception
Exception: UnexpectedTypeException: Expected Number, given Object

  • In the time since you used this, type checking was added and is on by default.  You are probably using a current SDK (7.2.1 is the most recent)

    To see if this is the issue, in your monkey.jungle file, add

    project.typecheck=0

    This turns typechecking off for that app, and if your app then runs, you can look at making your app "type checking friendly"

  • He got a runtime exception. How is that related to compile time type check?

  • Just suggesting something to try,,,  Could there have been warnings while compiling that weren't mentioned here?

  • What do you suggest?  

  • Sorry, maybe I don't know syntax of .jungle files, but when I write this and try complate, I have error:


    ERROR: unknown:0: A valid 'project.manifest' property was not defined within a jungle file.
    ERROR: monkey.jungle:2: mismatched input '=' expecting {'.', '-', ID, DIGIT, 'manifest', 'sourcePath', 'excludeAnnotations', 'resourcePath', 'lang', 'barrelPath', 'annotations'}
    ERROR: monkey.jungle:2: mismatched input '0' expecting {'.', '[', '/', '\', '~', '$', NEWLINE, ID, 'manifest', 'sourcePath', 'excludeAnnotations', 'resourcePath', 'lang', 'barrelPath', 'annotations', STRING, STRINGPATTERN}

     *  The terminal process terminated with exit code: 104.
     *  Terminal will be reused by tasks, press any key to close it.

  • Based on that error message, it sounds like you are using a very old SDK (circa 4.0.6 - I was able to recreate that jungle syntax error with 4.0.6) Even 4.1.6 (from November 2022) is able to handle this syntax.

    I would suggest using the latest SDK (7.2.1). I tried both 7.2.0 and 7.2.1, and was unable to recreate your problem with Time.now().

    EDIT: Having said that, I can't reproduce the problem with Time.now() using SDK 4.0.6 either :/

    I would also make use the SDK manager to make sure you have all of the latest devices (cliche advice, I know.)

  • Sounds like you are using an old SDK.... 7.2.1 is the latest.

  • Could there have been warnings while compiling that weren't mentioned here?

    How would turning off compile-time type checking avoid runtime type errors? As discussed ad nauseum, all other things being equal, turning off type checking can only increase the number of runtime type errors, never decrease them (think about it). The main reason for turning off type checking is bc of *compile-time* type errors which are preventing you from building your project, and you don't want to fix them (yet).

    And if there were warnings, how would turning off compile-time type checking help? So you don't see the warnings anymore, which accomplishes what? Certainly won't accomplish getting rid of any runtime type errors.

    That suggestion is worse than a waste of time, bc it gives the reader the false impression that turning off compile time type checking can "fix" a runtime type error (or that turning on compile time type checking can cause runtime type errors.) The net effect is to discourage people from using this very helpful feature. (It's on by default for a reason.)

    It's ironic bc you are usually the first person to tell everyone that Monkey Types is compile-time only. But for some reason whenever there's any problem where the cause is unknown, the first suggestion is "have you tried turning off type checking????"

    EDIT: I'll admit that in this case, it revealed that OP is using an old SDK. But we could've also just asked them what SDK they're using.

  • Error isn't probably in this line but I suppose you should use now.value() as number is expected