Quantcast
Viewing all articles
Browse latest Browse all 8068

Init Function Won't Answer Call

Running Studio 3.2.3 and SDK 3.2.x on OSX Mavericks. Developing for Android and iOS devices. I have a main routine that calls an initialization function in a widget. I am getting an error:

message = "'null' is not an object (evaluating 'APP.DashboardMenu.init')"; [ERROR] : name = TypeError;

Calling function code segment:

buildMenu: function(_nodes) {
        //APP.log("debug", "APP.buildMenu");
 
        //console.log(_nodes);
 
        APP.DashboardMenu.init({
            nodes: _nodes
 
        });
Function called:
/**
 * The dashboard menu widget
 * 
 * @class Widgets.com.bespokenIT.dashboardMenu
 */
 
var nodes = [];
//var color;
console.log('i got to the init function'); // this line is printed => $.init() was actually called
 
/**
 * Initializes the dashboard menu
 * @param {Object} _params
 * @param {Array} _params.nodes The nodes (menu items) to show in the dashboard menu as defined by the JSON configuration file (app.json)
 */
$.init = function(_params) {
 
  console.log('i am inside the init function');  // this line is never printed to the console before error is displayed
 
  // sections = []; 
  // var  nodes = [];
 
 
    for(var i = 0; i < _params.nodes.length; i++) {
 
        var tab = Ti.UI.createView({
            id: _params.nodes[i].id,
            height: Ti.UI.SIZE,
            layout: 'horizontal',
            left: "10dp",
            right: "5dp",
            top: Alloy.Globals.margin,
            width: "60dp"
        });
 
        var label = Ti.UI.createLabel({
            text: _params.nodes[i].title,
            height: Ti.UI.SIZE,
            color: '#000',
            textAlign: 'center',
            top: "5dp",
            touchEnabled: false,
            width: Ti.UI.FILL
        });
 
        if(_params.nodes[i].image) {
            var icon = Ti.UI.createImageView({
                image: _params.nodes[i].image,
                top: "0dp",
                left: Alloy.Globals.margin,
                height: Ti.UI.SIZE,
                width: Ti.UI.SIZE,
                preventDefaultImage: true
            });
 
            tab.add(icon);
        }
 
        tab.add(label);
        nodes.push(tab);
 
 
        $.Nodes.add(nodes[i]);
    }
 
    // We have to remove before adding to make sure we're not duplicating
    $.Nodes.removeEventListener("click", handleClick);
    $.Nodes.addEventListener("click", handleClick);
};
 
/**
 * Handles a click event on the nodes container
 * @param {Object} _event The event
 */
/*
 
function handleClick(_event) {
    if(typeof _event.index !== "undefined") {
        $.setIndex(_event.index);
    }
};*/
 
 
/**
 * Builds out the dashboard layout
 * @param {Object} _nodes The tab items to show in the side menu
 * @private
 */
 
 
/**
 * Clears all items from the side menu
 */
$.clear = function() {
    $.Nodes.setData([]);
    $.Nodes.removeAllChildren();
};
 
/**
 * Sets the indexed item as active
 * @param {Object} _index The index of the item to show as active
 */
 
/*
$.setIndex = function(_index) {
    $.Nodes.selectRow(_index);
};*/
 
 
// Move the UI down if iOS7+
if(OS_IOS && parseInt(Ti.Platform.version.split(".")[0], 10) >= 7) {
    $.Nodes.top = "20dp";
}
In debugging the error, I noticed the $.init () is not been processed because I get the console display entered before the routine but the console statement inside the routine is never printed. I was trying to use this tier one approach to see where the null object is coming from since the routine is actually called.

I also verified that the params (nodes) in the calling function actually exist. What stops the init function from processing the first statement (console.log) ? I appreciate any other issues anyone can pick up in this program flow and statements. Thanks a million.


Viewing all articles
Browse latest Browse all 8068

Trending Articles