This is my first attempt at building a simple widget and I am having difficulty with this particular error on the makeWebRequest command.
Invalid '$.Toybox.Lang.Method(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary) as Void' passed as parameter 4 of type 'PolyType<(callback(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String) as Void) or (callback(responseCode as $.Toybox.Lang.Number, data as Null or $.Toybox.Lang.Dictionary or $.Toybox.Lang.String, context as $.Toybox.Lang.Object) as Void)>'.
Also the terminal shows the process was terminated with exit code: 105.
Any help would be appreciated.
import Toybox.Application;
import Toybox.Lang;
import Toybox.WatchUi;
import Toybox.Communications;
import Toybox.System;
import Toybox.Graphics;
import Toybox.Time;
class BitcoinOnlyApp extends Application.AppBase {
function initialize() {
AppBase.initialize();
}
// onStart() is called on application start up
function onStart(state as Dictionary?) as Void {
makeRequest();
}
// 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>? {
return [ new BitcoinOnlyView("LOADING") ] as Array<Views or InputDelegates>;
}
// set up the response callback function
function onReceive(responseCode as Number, data as Dictionary?) as Void {
//Ui.switchToView(new GarminJSONWebRequestWidgetView("onReceive: " + URL + "\n" + responseCode + " " + data), null, Ui.SLIDE_IMMEDIATE);
System.println(responseCode);
System.println(data);
//Get only the JSON data we are interested in and call the view class
WatchUi.switchToView(new BitcoinOnlyView(data.get("usd")), null, WatchUi.SLIDE_IMMEDIATE);
}
function makeRequest() as Void {
var url = "https://api.coingecko.com/api/v3/simple/price?";
var params = {"ids" => "bitcoin",
"vs_currencies" => "usd"};
var options = {
:method => Communications.HTTP_REQUEST_METHOD_GET,
:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON,
:headers => {
"Content-Type" => "Communications.REQUEST_CONTENT_TYPE_URL_ENCODED",
"Accept" => "application/json"}
};
Communications.makeWebRequest(url, params, options, method(:onReceive));
}
function getApp() as BitcoinOnlyApp {
return Application.getApp() as BitcoinOnlyApp;
}
}