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();
            }
        }
    }
}

Parents
  • Hi,
    I ended up discovering the cause, but I can't understand why it happens: I have a hierarchy of modules (inside a barrel) where I usually use a nomenclature identical to the one used inside "Toybox", but with a different root name ("XSL" in my case). For example I have modules called "XSL.Graphics", "XSL.Time" and "XSL.WatchUi" where I define types that extend or complement existing types in "Toybox.Graphics", "Toybox.Time" and "Toybox.WatchUi" .

    The view that was giving the error is inside the "XSL.WatchUi" module. As soon as I changed the module name (eg to "XSL.WatchUi2") the error disappeared.

    Apparently(?) the VM was trying to find the "KeyEvent" symbol inside "XSL.WatchUi" instead of inside "Toybox.WatchUi".

    So, I ask: is it wrong/unadvised to give the sub-modules the same names as the sub-modules of "Toybox" even though the root name is different?

Comment
  • Hi,
    I ended up discovering the cause, but I can't understand why it happens: I have a hierarchy of modules (inside a barrel) where I usually use a nomenclature identical to the one used inside "Toybox", but with a different root name ("XSL" in my case). For example I have modules called "XSL.Graphics", "XSL.Time" and "XSL.WatchUi" where I define types that extend or complement existing types in "Toybox.Graphics", "Toybox.Time" and "Toybox.WatchUi" .

    The view that was giving the error is inside the "XSL.WatchUi" module. As soon as I changed the module name (eg to "XSL.WatchUi2") the error disappeared.

    Apparently(?) the VM was trying to find the "KeyEvent" symbol inside "XSL.WatchUi" instead of inside "Toybox.WatchUi".

    So, I ask: is it wrong/unadvised to give the sub-modules the same names as the sub-modules of "Toybox" even though the root name is different?

Children
  • I think you can because namespaces. But I use a slightly different approach as I use OPN.SubModule.WatchUi as module names, which I than import in my code with using OPN.Submodule.WatchUi as Ui;  This way I avoid any chance of name space collisions. I think a small test barrel to expose the behavior/bug is the best approach.