here's my code in pomodoroApp.mc in Monkey C
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
class PomodoroApp extends Application.AppBase {
private var _view as PomodoroView?;
function initialize() {
AppBase.initialize();
}
// onStart() is called on application start up
function onStart(state as Dictionary?) as Void {
}
// onStop() is called when your application is exiting
function onStop(state as Dictionary?) as Void {
}
// Return the initial view of your application here
function getInitialView() as Array<Views or InputDelegates>? {
_view = new PomodoroView();
return [ _view, new PomodoroDelegate() ] as Array<Views or InputDelegates>;
}
// Returns main view instance
function getView() as PomodoroProView? {
return _view;
}
}
function getApp() as PomodoroApp {
return Application.getApp() as PomodoroApp;
}
// Returns main view instance
function getView() as PomodoroProView? {
return Application.getApp().getView();
}
its giving me ERROR
ERROR: marq2aviator: C:\garmin\Aplikacje\Pomodoro\source\PomodoroProApp.mc:21: Cannot override '$.Toybox.Application.AppBase.getInitialView' with a different return type.
What's going on? How to fix this Error and not get the same error in future?
Thank you in advance!
Tobiasz
here's my code in pomodoroApp.mc in Monkey C
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
class PomodoroApp extends Application.AppBase {
private var _view as PomodoroView?;
function initialize() {
AppBase.initialize();
}
// onStart() is called on application start up
function onStart(state as Dictionary?) as Void {
}
// onStop() is called when your application is exiting
function onStop(state as Dictionary?) as Void {
}
// Return the initial view of your application here
function getInitialView() as Array<Views or InputDelegates>? {
_view = new PomodoroView();
return [ _view, new PomodoroDelegate() ] as Array<Views or InputDelegates>;
}
// Returns main view instance
function getView() as PomodoroProView? {
return _view;
}
}
function getApp() as PomodoroApp {
return Application.getApp() as PomodoroApp;
}
// Returns main view instance
function getView() as PomodoroProView? {
return Application.getApp().getView();
}
its giving me ERROR
ERROR: marq2aviator: C:\garmin\Aplikacje\Pomodoro\source\PomodoroProApp.mc:21: Cannot override '$.Toybox.Application.AppBase.getInitialView' with a different return type.
What's going on? How to fix this Error and not get the same error in future?
Thank you in advance!
Tobiasz
1 Answer
Reset to default 0You overwrote the "getInitialView" method so it's allowed to return other parameters than the super class ones and also Null:
function getInitialView() as Array<Views or InputDelegates>? {
// this is an issue: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_view = new PomodoroView();
return [ _view, new PomodoroDelegate() ] as Array<Views or InputDelegates>;
}
Either use the return type from the super class (Toybox.Application.AppBase) or leave it untyped (the return type is then implied from the super class).
getInitialView() as [ WatchUi.Views ] or [ WatchUi.Views, WatchUi.InputDelegates ]
Since you're defining a type for the array you're returning in the return statement aswell, you will have to adjust this piece of code aswell in the same manner.
Official documentation