Acknowledged

Symbol Not Found Error: Could not find symbol 'KeyEvent'

Hi,

I have a class derived from WatchUi.View, that when is being shown gives the following error whenever I press the (physical) button on the clock (vívoactive 3):

(from CIQ_LOG.YML)

Error: Symbol Not Found Error
Details: "Could not find symbol 'KeyEvent'"
Time: 2022-07-20T14:17:47Z
Part-Number: XXX-XXXXX-00
Firmware-Version: '8.10'
Language-Code: por
ConnectIQ-Version: 4.1.4
Filename: -----
Appname: -----
Stack:
- pc: 0x30001d07
- pc: 0x30001fb0

In the simulator, I also can see the error:

Error: Symbol Not Found Error
Details: Could not find symbol 'KeyEvent'
Stack:
- handleEvent() at D:\grmn\prj\di\connectiq\toolchain\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\WatchUi.mb:1065 0x30002252
- handleEvent() at D:\grmn\prj\di\connectiq\toolchain\mbsimulator\submodules\technology\monkeybrains\virtual-machine\api\WatchUi.mb:1262 0x300024fd

The curious thing is that neither the class derived from the View nor the one from BehaviorDelegate has any reference to WatchUi.KeyEvent (in fact now they do, as I added it to try to see if I could overcome the problem by forcing the use of the "KeyEvent" symbol in those classes... with no success).

The stack trace seems to point to an internal API error.

Can anyone help?

Thank you

UPDATE

I found that the VM appears to be getting confused when the (user) namespace contains "WatchUi". Any class derived from WatchUi.View within a namespace or subnamespace with that token (eg XYZ.WatchUi, X.Y.Z.WatchUi or X.Y.Z.WatchUi.Sub) will produce the error when the physical button is clicked.

The following example works fine, but when we change the subnamespace from "WatchUi2" to "WatchUi" it will produce the error described above:

import Toybox.Lang;

using Toybox.Application;
using Toybox.WatchUi            as Ui;
using XYZ.WatchUi2              as XW;

class XYZApp extends Application.AppBase
{
    public function initialize()
    {
        AppBase.initialize();
    }

    public function getInitialView() as Lang.Array<Ui.Views or Ui.InputDelegates>?
    {
        var result = [ new XW.EmptyWindowView(), new XW.EmptyWindowDelegate() ] as Lang.Array<Ui.View or Ui.InputDelegate>;
        return result;
    }
}

import Toybox.Lang;

using Toybox.Graphics           as Gfx;
using Toybox.WatchUi            as Ui;

module XYZ
{
    module WatchUi2
    {
        class EmptyWindowView extends Ui.View
        {
            function initialize()
            {
                View.initialize();
            }

            // Load your resources here
            function onLayout(dc as Gfx.Dc) as Void
            {
            }

            // Called when this View is brought to the foreground. Restore the state of this View and prepare it to be shown.
            // This includes loading resources into memory.
            function onShow() as Void
            {
            }

            // Called when this View is removed from the screen. Save the state of this View here. This includes freeing resources from memory.
            function onHide() as Void
            {
            }

            // Update the view
            function onUpdate(dc as Gfx.Dc) as Void
            {
                View.onUpdate(dc);
            }
        }
    }
}

import Toybox.Lang;

using Toybox.WatchUi            as Ui;

module XYZ
{
    module WatchUi2
    {
        class EmptyWindowDelegate extends Ui.BehaviorDelegate
        {
            function initialize()
            {
                BehaviorDelegate.initialize();
            }
        }
    }
}

  • I'm playing with some views to see how overlays (layers) work and textareas, I noticed that when i say:

    using Toybox.Graphics as Gfx; I can use Graphics.COLOR_WHITE later on in a function. It should not know the namespace Graphics, but it does. So what I think happens is that you import stuff such as Toybox.WatchUI, you have your OWN module XYZ.WatchUI and than things start to break down rather quickly because it suddenly is accessing a namespace that it shouldn't know about.

    You can find an example here: https://gitlab.com/waterkip/ciq-demo-watch-app/-/blob/master/source/views/LegalView.mc

    The view should not be able to load/work, yet it does.

  • Feature request: Compile code inside posts Slight smile

  • Ahh, right, using Toybox.Graphics as Gfx. We cannot edit posts here (annoying!).

  • Curious: the compiler (using strict rules) only complains about Gfx...

  • Somewhat related, what do you expect to happen here?

    using Toybox.WatchUi as Ui;
    
    class SomeView extends Ui.View {
    
      function initialize() {
        Ui.View.initialize();
      }
      
      function onUpdate(dc as Gfx.Dc) {
        System.println("Yoo");
        View.onUpdate(dc);
      }
    
    }
    
    class OverlayViewDelegate extends Ui.BehaviorDelegate {
    
      function initialize() {
        Ui.BehaviorDelegate.initialize();
      }
    
      function onMenu() {
        System.println("Menu behavior triggered");
        return true;
      }
    
      function onSelect() {
        System.println("Select behavior triggered");
        return false;
      }
    
      function onBack() {
        Ui.popView(0 as Toybox.WatchUi.SlideType);
        return true;
      }
    
      function onNextPage() {
        System.println("Pressed on down");
        return false;
      }
    
      function onPreviousPage() {
        System.println("Pressed on up");
        return false;
      }
    
      function onKey(keyEvent) {
        Ui.requestUpdate();
        return true;
      }
    
    }

    I'm expecting:

    Error: Symbol Not Found Error
    Details: "Could not find symbol 'println'"

    I'm getting:

    Yoo

    And output on all the keypreses eventho I haven't imported/using Toybox.System.