SQLite - System.NullReferenceException: Object reference not set to an instance of an object

When I run this code:

var Observable = require("FuseJS/Observable");
var items = Observable();
var orderNumber = Observable();
var ticketListGlobal = null;
var validatedTicketsGlobal = null;
var sqlite = require('SQLite');
var db = sqlite.open("validadorbr.sqlite");

ticketListGlobal = this.Parameter.map(function(param) {
    ticketListGlobal = param.ticketListParam;
    debug_log( "Parameter value: " + ticketListGlobal );

    createTable();
    updateTicketList( ticketListGlobal );
    select();
    
    return ticketListGlobal;
});

function addItem() {
    for ( var i in ticketListGlobal ) {
        if ( ticketListGlobal[i].orderNumber == orderNumber.value ) {
            items.add( ticketListGlobal[i] );
        }
    }
}

function validateItem(ticket) {

}

function dropTable() {
    debug_log( "Executing dropTable method..." );
    db.execute( "DROP TABLE tickets_information" );
}

function select() {
    var r = db.query("SELECT * FROM tickets_information");
    debug_log(JSON.stringify(r));
}

function createTable() {
    debug_log( "Executing createTable method..." );
    var table = "CREATE TABLE IF NOT EXISTS tickets_information ( ";
        table += " event_id INTEGER, ";
        table += " order_number INTEGER, ";
        table += " order_type TEXT, ";
        table += " sector TEXT, ";
        table += " seat TEXT, ";
        table += " order_key TEXT, ";
        table += " order_status INTEGER, ";
        table += " validation_time TEXT );";
    db.execute( table );
}

function updateTicketList(tickets) {
    debug_log( "Executing updateTicketList method..." );
	// Iterate over the collection of data
	for ( var i in tickets ) {
		ticketUpdateOrInsertRow(tickets[i]);
	}
}

function ticketUpdateOrInsertRow(ticket) {
    debug_log( "eventId: " + ticket.eventId );
    debug_log( "n: " + ticket.orderNumber );
    debug_log( "k: " + ticket.orderKey );
    debug_log( "d: " + ticket.validationTime );
	db.execute( "INSERT INTO tickets_information (event_id, order_number, order_type, sector, seat, order_key, order_status, validation_time) VALUES (?,?,?,?,?,?,?,?)",
 				ticket.eventId, ticket.orderNumber, ticket.orderType, ticket.sector, ticket.seat, ticket.orderKey, ticket.orderStatus, ticket.validationTime);
}


function goToLogin() {
    router.goto("login");
}

module.exports = {
    orderNumber: orderNumber,
    items: items,
    addItem: addItem,
    validateItem: validateItem,
    goToLogin: goToLogin,
    ticketListGlobal: ticketListGlobal,
    validatedTicketsGlobal: validatedTicketsGlobal
}

The JSON data is like that (the original has about 1000 registers):

{"status":"Ok","message":"Success","content":[{"eventId":192,"orderNumber":89789,"orderType":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"275","orderKey":"0ADMwQzMwADMykTMwADMwADM4ADMwADMwADM","orderStatus":0,"validationTime":null},{"eventId":192,"orderNumber":104915,"orderType":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"156","orderKey":"0ADN4kzMwADMykTMwADMwADM4ADMwADMwADM","orderStatus":0,"validationTime":null},{"eventId":192,"orderNumber":107512,"orderType":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"440","orderKey":"0ATN3ADNwADMykTMwADMwADM4ADMwADMwADM","orderStatus":0,"validationTime":null},{"eventId":192,"orderNumber":94608,"orderType":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"241","orderKey":"0cDM3UzMwADMykTMwADMwADM4ADMwADMwADM","orderStatus":0,"validationTime":null},{"eventId":192,"orderNumber":98971,"orderType":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"317","orderKey":"0cTN1czMwADMykTMwADMwADM4ADMwADMwADM","orderStatus":0,"validationTime":null}

I’m getting this error:

System.NullReferenceException: Object reference not set to an instance of an object
  at Fuse.Scripting.V8.Context.ThrowPendingExceptions () <0x1d913b90 + 0x0003f> in <filename unknown>:0 
  at Fuse.Scripting.V8.Object.CallMethod (System.String name, System.Object[] args) <0x1d975cf8 + 0x0041f> in <filename unknown>:0 
  at Fuse.Reactive.Observable..ctor (Fuse.Reactive.ThreadWorker worker, Fuse.Scripting.Object obj, Boolean supressCallback) <0x1d979008 + 0x00289> in <filename unknown>:0 
  at Fuse.Reactive.ThreadWorker.CreateMirror (System.Object obj) <0x1d977588 + 0x0021f> in <filename unknown>:0 
  at Fuse.Reactive.ThreadWorker.Reflect (System.Object obj) <0x1d976e18 + 0x000fb> in <filename unknown>:0 
  at Fuse.Reactive.ObjectMirror..ctor (Fuse.Reactive.ThreadWorker worker, Fuse.Scripting.Object obj) <0x1d977ea0 + 0x000f7> in <filename unknown>:0 
  at Fuse.Reactive.ThreadWorker.CreateMirror (System.Object obj) <0x1d977588 + 0x0026b> in <filename unknown>:0 
  at Fuse.Reactive.ThreadWorker.Reflect (System.Object obj) <0x1d976e18 + 0x000fb> in <filename unknown>:0 
  at Fuse.Reactive.JavaScript+EvaluateDataContext.Evaluate () <0x1d96ef40 + 0x00033> in <filename unknown>:0 
  at Fuse.Reactive.ThreadWorker.RunInner () <0x1d911860 + 0x0039f> in <filename unknown>:0 

The curious thing is the app saves 12 registers and then the error occurs.

Here is the output of my select:

[{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_num
ber":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"17","order_key":"192091645","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"23227","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"19","order_key":"192091646","order_status":"1","validation_time":"03/05/2017 21:55:20"},{"event_id":"192","order_number":"42646","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"57","order_key":"4cDO4YTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 23:00:32"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"32","order_key":"5cTO3cTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"},{"event_id":"192","order_number":"37056","order_type":"PLATEIA | PROMOCIONAL 1KG DE ALIMENTO","sector":"PLATÉIA","seat":"258","order_key":"5MTNxQTMwADMwADMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:53:12"},{"event_id":"192","order_number":"45334","order_type":"PLATEIA | MEIA-ENTRADA","sector":"PLATÉIA","seat":"30","order_key":"wgTO3cTMwADMykTMwADMwADM4ADMwADMwADM","order_status":"1","validation_time":"03/05/2017 22:34:09"}]

Any suggestions?

I solved this changing my JSON data. It had some special characters and null values that was causing problems. So, I replaced those characters on server side and returned a fitter JSON.

Fuse could throws a more specific exception, for sure it would be useful, i.e. “It was not possible to execute SQL”, or something like that… :wink: