Acknowledged

6.2.0 Cannot call function in Class - worked flawlessly with SDK 4.2.4

Cannot call function    curRadarBattery = myBikeRadarListener.getMyBattery();   

Gives an error:
ERROR: edge1040: C:\Garmin_IQ_Projekte\RadarBattery\source\RadarBatteryView.mc:53,8: Cannot find symbol ':getMyBattery' on class definition '$.myBikeRadarListener'.
Worked flawlessly with SDK 4.2.4  !

import Toybox.Activity;
import Toybox.Lang;
import Toybox.Time;
import Toybox.WatchUi;
import Toybox.AntPlus;


var myRadarBattery = 0;
class myBikeRadarListener extends AntPlus.BikeRadarListener {

    function initialize() {
        AntPlus.BikeRadarListener.initialize();
    }

    function onBatteryStatusUpdate(data) {
        if ( data != null ) {
            if ( data.batteryStatus != null ) {
                myRadarBattery = data.batteryStatus; 
            }
        } else {    
            myRadarBattery = 0;            
        }
    }

    function getMyBattery() {
        return myRadarBattery;
    }    

}


class RadarBatteryView extends WatchUi.SimpleDataField {

    var radarlistener;
    var bikeRadar;
    var curRadarBattery = 0;
    var radarBatStatus = "unknown";


    // Set the label of the data field here.
    function initialize() {
        SimpleDataField.initialize();

        label = "Radar Battery";

        radarlistener = new myBikeRadarListener();
        bikeRadar = new AntPlus.BikeRadar(radarlistener);

    }

    function compute(info as Activity.Info) as Numeric or Duration or String or Null {

        curRadarBattery = myBikeRadarListener.getMyBattery();    
 
        //for testing:
        //curRadarBattery = 3;

        if ( curRadarBattery == 0 ) {
            radarBatStatus = "unknown";
        } else if ( curRadarBattery == 1 ) {
            radarBatStatus = "new";             // 100%
        } else if ( curRadarBattery == 2 ) {
            radarBatStatus = "good";             // 75%
        } else if ( curRadarBattery == 3 ) {
            radarBatStatus = "okay";             // 50%
        } else if ( curRadarBattery == 4 ) {
            radarBatStatus = "low";             // 30%
        } else if ( curRadarBattery == 5 ) {
            radarBatStatus = "critcal";             // 10%
        } else if ( curRadarBattery == 7 ) {
            radarBatStatus = "invalid";           
        } else if ( curRadarBattery == 8 ) {
            radarBatStatus = "cnt?";
        }

        return radarBatStatus;
    }

}

  • Thank you for your input. As  suggested, I now simply use the global variable and it works.

    But since I‘m new to all that and willing to learn, I will test your suggestion! Thanks for that!

  • As far as I can tell, that code should never have compiled or run.

    class myBikeRadarListener extends AntPlus.BikeRadarListener {
    
        function getMyBattery() {
            // ...
        }    
    }
    
    
    class RadarBatteryView extends WatchUi.SimpleDataField {
    
        var radarlistener;
    
        function initialize() {
            // ...
            radarlistener = new myBikeRadarListener();
            // ...
        }
    
        function compute(info as Activity.Info) as Numeric or Duration or String or Null {
    
            // ...
            curRadarBattery = myBikeRadarListener.getMyBattery();    
            // ...
        }
    }

    myBikeRadarListener is a type, and you are calling a non-static function on that type. You should only be calling non-static functions on instances. The call should be..

    curRadarBattery = radarListener.getMyBattery();

    I'd expect the type checker to call you out on that, but maybe you aren't using the type checker?

    - you have the same exact problem. I don't know what is going on in RefreshSettings, but if that function references any data in the firstscreen class, you need to pass an instance of firstscreen to the secondscreen somehow (either via a global, a constructor parameter, or a setter).

  • i have a similar issue too. Also my code is very bad... but i really need an hand now because many of my app are not working anymore:

    The problem is the following:

    in a file (file01.mc) i have the mainclass

    class firstscreen extends WatchUi.View
    {
    ...
        function RefreshSettings()
            {...}
    ...
    }
    in a different file (file02.mc) (another screen) i have another class
    class secondscreen extends WatchUi.View
    {
    ...
        public function onUpdate(dc as Dc) as Void
            {
               ....
                firstscreen.RefreshSettings();
               .....
              }
    it works fine until 6.2.0 now the error is "ERROR: fenix5: D:\7xxx\xxxx\file02.mc:191,24: Cannot find symbol ':RefreshSettings' on class definition '$.firstscreen '. "
    thank you very much for help.... :'(
  • Sorry for "horrible code"...
    (I've only been on Monkey C for a few months and was really proud that the code worked at all ;-)

    But thank you for your advice - it works now!