英文:
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 ':setText' on type 'PolyType<Null or $.Toybox.WatchUi.Drawable>'
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("$1$:$2$", [clockTime.hour, clockTime.min.format("%02d")]);
var view = View.findDrawableById("TimeLabel");
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("TimeLabel");
into
var view = View.findDrawableById("TimeLabel") as Text;
done!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论