Error: Symbol Not Found Error Details: Could not find symbol 'makeRequest'

Warning: newbie alert:

I've seen similar on the forum but can't work this one out; My code is basically straight out of one of the examples and all the functions are inside a class.

class InputView extends WatchUi.View {
    // set up the response callback function
	// Straight out of the manual ... 
   	function onReceive(responseCode, data) {\
   		myDebug("onReceive() called with code=" + responseCode);
    	// sdata = {}; // Reset our global data??
    	if (responseCode == 200) {
       		sdata = data; // Do we need to copy it to make it global for some reason? Apparently we do!
       		stationid = sdata.keys();
       		stations = sdata.size();
       		utclastsuccess = utctimenow();
       		changePage(pageid);       		
    	} else {
           	System.println("onReceive() failed. Response: " + responseCode); // print response code
           	myDebug("Can't get data: " + responseCode);
           	makeItRed("Can't get data :(", responseCode);
       	}
       	request_in_progress = false;
   	}

	function makeRequest() {
		utclastchecked = utctimenow();
		myDebug("makeRequest() called ...");
		
		if (request_in_progress) {
			myDebug("makeRequest() aborting as request already in progress");	    
        	return;
        }
        
        var params = null; // var params = { "definedParams" => "someParam" };
        
		var headers = {
			"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED,
		};
       	var options = {   
       		:headers => headers,
           	:method => Communications.HTTP_REQUEST_METHOD_GET,
           	:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
       	};

       	// Make the Communications.makeWebRequest() call
        // Communications.makeWebRequest(url, params, options, method(:onReceive));
        request_in_progress = true;
        Communications.makeWebRequest(url, params, options, method(:onReceive));
    }
       
	function initialize() {
	    View.initialize();
        
        station_name = "";
        wind_dir = "Getting data ...";
        wind_speed = "";
        last_update = "";
        
        makeRequest(); // This works
    }


	function changePage(i) {

The initial call to makeRequest() and subsequent :onReceive callback work fine but I want to update the data from time to time if it gets old and if I try and call makeRequest() from inside the changePage() function it mostly bombs with this

Error: Symbol Not Found Error
Details: Could not find symbol 'makeRequest'

changePage() is in the same class and is called from another class that handles all the button pressing. 

Is that the problem? Apologies as I'm sure it's a simple lack of understanding on my part but I just can't work it out.

EDIT: Further to this if I move changePage() out of InputView and make it global (where I guess it probably should be) and call InputView.makeRequest() I get the old 

Error: Symbol Not Found Error
Details: Could not find symbol 'method'

  • I'm not really sure what is going on. It is hard to tell because you're not providing the code that is calling makeRequest that is supposed to be failing. My guess is that changePage isn't modifying any state in InputView and you are calling changePage in such a way that there is no object. It would help to see what the code calling changePage looks like.

    As for the last error you mention, I'm guessing the failure is occurring on this line:

    Communications.makeWebRequest(url, params, options, method(:onReceive));

    If you put that code in a global or a module function, it should fail with a symbol not found error. The last parameter is a call to a function named method. This function is a method on the Lang.Object class, so it is available to anything that inherits from Object. Modules do not inherit from Object, so the function is not found.

    If you have a function named onReceive defined in the same module, you could write this

    Communications.makeWebRequest(url, params, options, new Lang.Method(MyModule, :onReceive));

    Of course you could also do the object-oriented thing and define a class for making the request and maybe another for handling the response.

  • Thank you Travis. Very much appreciated.

    Given I'm in lockdown I will attempt to go the object-oriented way** and get it right; properly. 

    **somewhat confusing for someone who hasn't coded in a VERY long time and finished uni just as OO was starting to become a thing (consequently a very "top-down" coder :-/ )

  • Thanks kindly again Travis. Your reply got me thinking properly. The solution, in my case, was to go the OO way and create a new instance each time. I've noticed others have had the same problem over the years so in case someone's scouring the forums as I was, this works really nicely for me. (Please let me know if you see any holes in it!):

    class Request { 
    	
    	function onReceive(responseCode, data) {
    
        	if (responseCode == 200) {
           		sdata = data;
           		stationId = sdata.keys();
           		stations = sdata.size();
           		utcLastSuccess = utcTimeNow();
           		changePage(0);
        	} else {
               	errorScreen("Can't get data", responseCode);
           	}
           	requestInProgress = false;
       	}
    	
    	public function initialize() {
    		if (requestInProgress) {
    			// Do nothing
    			myDebug("Request.initialize() aborting as request already in progress");	    
            } else {
                // var params = { "definedParams" => "someParam" };
    	        var params = null; 
    	        
    			var headers = {
    				"Content-Type" => Communications.REQUEST_CONTENT_TYPE_URL_ENCODED,
    			};
    			
    	       	var options = {   
    	       		:headers => headers,
    	           	:method => Communications.HTTP_REQUEST_METHOD_GET,
    	           	:responseType => Communications.HTTP_RESPONSE_CONTENT_TYPE_JSON
    	       	};
    	
    	        Communications.makeWebRequest(url, params, options, method(:onReceive));
    	        requestInProgress = true;        
    	        utcLastChecked = utcTimeNow();       
    		}
    	}
    }