“Cannot find symbol ‘setText’…”

huangapple go评论87阅读模式
英文:

Garmin and Monkey C "Cannot find symbol ':setText'..."

问题

在尝试创建一个Garmin WatchFace时,我迅速遇到了以下错误,但不幸的是,我不知道为什么会发生,也许有人可以帮助你?

在类型'PolyType<Null or $.Toybox.WatchUi.Drawable>'上找不到符号':setText'

我使用以下代码:

function onUpdate(dc as Dc) as Void {
    setClockDisplay();
    setDateDisplay();
    setBatteryDisplay();
    setStepCountDisplay();
    setStepGoalDisplay();
    setNotificationCountDisplay();
    setHeartrateDisplay();
        // 调用父级的onUpdate函数以重新绘制布局
    View.onUpdate(dc);
}

private function setClockDisplay() {
	var clockTime = System.getClockTime();
    var timeString = Lang.format("$1$:$2$", [clockTime.hour, clockTime.min.format("%02d")]);	
    var view = View.findDrawableById("TimeLabel");	
    view.setText(timeString);
}    

}

这个错误出现在所有的.setText()方法上,这种情况下共9次。

我已经尽力尝试了一切我能想到的。
英文:

I want to try a garmin WachFace and came across very quickly folgnden error, but unfortunately I do not know why it occurs, maybe someone can help you?

Cannot find symbol &#39;:setText&#39; on type &#39;PolyType&lt;Null or $.Toybox.WatchUi.Drawable&gt;&#39;

I use the following code:


    function onUpdate(dc as Dc) as Void {
        setClockDisplay();
        setDateDisplay();
        setBatteryDisplay();
        setStepCountDisplay();
        setStepGoalDisplay();
        setNotificationCountDisplay();
        setHeartrateDisplay();
            // Call the parent onUpdate function to redraw the layout
        View.onUpdate(dc);
    }

    private function setClockDisplay() {
    	var clockTime = System.getClockTime();
        var timeString = Lang.format(&quot;$1$:$2$&quot;, [clockTime.hour, clockTime.min.format(&quot;%02d&quot;)]);	
        var view = View.findDrawableById(&quot;TimeLabel&quot;);	
        view.setText(timeString);
    }    
}

The error is thrown for all .setText(). In this case 9 times

I have tried everything I could think of.

答案1

得分: 4

以下是已经翻译好的部分:

解决问题的方法如下:

var view = View.findDrawableById("TimeLabel");

改为

var view = View.findDrawableById("TimeLabel") as Text;

完成!

英文:

the following solves the problem:

change

var view = View.findDrawableById(&quot;TimeLabel&quot;);

into

var view = View.findDrawableById(&quot;TimeLabel&quot;) as Text;

done!

huangapple
  • 本文由 发表于 2023年2月14日 00:32:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定