最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

monkeyc - What the ERROR: "DEVICE: C:PATHsourceAPP.mc:21: Cannot override '$.Toybox.Application.AppBase.getInit

programmeradmin3浏览0评论

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

Share Improve this question asked Mar 17 at 23:12 TobiaszTobiasz 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论