简体   繁体   中英

Connect IQ unexpected type Error when using setText

When a menu item is pressed I want to set the text of a label, however i'm getting the errors: "Failed invoking <symbol>" and "Unexpected Type Error".

In my menu delegate I have:

using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
using Toybox.Position as Position;

class DiscGolfMenuDelegate extends Ui.MenuInputDelegate {

    var _view;

    function initialize() {
        MenuInputDelegate.initialize();
        _view = new DiscGolfView();
    }

    function onMenuItem(item) {
        if (item == :measure_throw) {
            Sys.println("item 1");
            _view.setLongestThrow("yeet");
        } else if (item == :start_game) {
            Sys.println("item 2");
        }
    }

}

the setLongestThrowFunction is located in my View class and looks like:

function setLongestThrow(msg) {
    longest_throw_label.setText(msg);
}

It doesn't make sense why i'd get an unexpected type error as i'm passing through a string. Anyone see something I don't? thanks.

I believe the problem is not with _view or the string passed to setText , but with longest_throw_label .

The issue is likely that you initialize _view in the menu constructor, but the view has not been laid out yet (the system hasn't called _view.onLayout(dc) because the view hasn't been pushed).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM