cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Wrapped java.lang.NullPointerException

Tomellache2B
14-Alexandrite

Wrapped java.lang.NullPointerException

Below is my code:

 

//creating an infotable

let Log = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
infoTableName: "InfoTable",
dataShapeName: "DataShape"
});

 

//Defining date variable

var currentDate;

 

//assigning valueList variable to my infoTable property that contains values (current it only has one row)

var valuesList = Things["TestThing1"].infoTableThingProperty;

 

//loop through the infotable above
for(var i=0; i<valuesList.length; i++){

// new object 
newEntry = {
duration:valuesList[i].duration,
source: valuesList[i].Source,
Name: valuesList[i].Name,
Type: valuesList[i].Type,
StartTime: valuesList[i].StartTime,
EndTime: valuesList[i].faultEndTime,
Voltage: valuesList[i].Voltage,
Text: valuesList[i].Text

};

//adding my object values to the infotable
Log.AddRow(newEntry);
}

 

//adding my infotable to the stream 

var newLog = Things["SinkWorx.PwrSupplyError_Stream"].AddStreamEntries({
values: Log /* INFOTABLE {"dataShape":"StreamEntryWithValues"} */
});

 

//output result

let result = Log;

 

I keep getting the error above, I am not sure why.

Does anyone know how I can fix it?

 

Kind Regards,

TB

1 ACCEPTED SOLUTION

Accepted Solutions

 

 

duration: valuesList[i].duration,
source: valuesList[i].Source,
Name: valuesList[i].Name,
Type: valuesList[i].Type,
StartTime: valuesList[i].StartTime,
EndTime: valuesList[i].faultEndTime,
Voltage: valuesList[i].Voltage,
Text: valuesList[i].Text

 

 

Any o these INTEGER/NUMBER values might by NULL.

 

Try only with STRING values and change accordingly

View solution in original post

5 REPLIES 5

try this..

//creating an infotable
let streamEntryData = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
	infoTableName: "InfoTable",
	dataShapeName: "StreamEntryWithValues"
});
//Defining date variable
var currentDate;
//assigning valueList variable to my infoTable property that contains values (current it only has one row)

var valuesList = Things["TestThing1"].infoTableThingProperty;

//loop through the infotable above
for (var i = 0; i < valuesList.length; i++) {
    let Log = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
        infoTableName: "InfoTable",
        dataShapeName: "DataShape"
    });
	// new object 
	newEntry = {
		duration: valuesList[i].duration,
		source: valuesList[i].Source,
		Name: valuesList[i].Name,
		Type: valuesList[i].Type,
		StartTime: valuesList[i].StartTime,
		EndTime: valuesList[i].faultEndTime,
		Voltage: valuesList[i].Voltage,
		Text: valuesList[i].Text

	};
	//adding my object values to the infotable
	Log.AddRow(newEntry);
    
    // StreamEntryWithValues entry object
    let streamEntry = {
        sourceType: undefined,// STRING
        values: Log,// INFOTABLE
        location: undefined,// LOCATION
        source: undefined,// STRING
        tags: undefined,// TAGS
        timestamp: new Date()// DATETIME
    };
	streamEntryData.AddRow(newEntry);
}

//adding my infotable to the stream 
var newLog = Things["SinkWorx.PwrSupplyError_Stream"].AddStreamEntries({
	values: streamEntryData /* INFOTABLE {"dataShape":"StreamEntryWithValues"} */
});

//output result
let result = streamEntryData;

Hi @Sathishkumar_C  thank you for the suggestion but I am still getting the same error.

 

 

 

duration: valuesList[i].duration,
source: valuesList[i].Source,
Name: valuesList[i].Name,
Type: valuesList[i].Type,
StartTime: valuesList[i].StartTime,
EndTime: valuesList[i].faultEndTime,
Voltage: valuesList[i].Voltage,
Text: valuesList[i].Text

 

 

Any o these INTEGER/NUMBER values might by NULL.

 

Try only with STRING values and change accordingly

Hi, thank you for the suggestion.

 

I found that the error was with the subscriptions calling the service. 

So I removed the infotable property that I was loping through and instead used the built-in service: "queryStreamEntriesWithData" and wrote an actual query which I then passed to this built-in service.

 

Also the subscription I added some conditional statements that need to pass before calling the service.

This solved the issue.

 

Best Regards,

TB

DanZ
15-Moonstone
(To:Tomellache2B)

To narrow down the source of the error, put everything in a try-catch clause and log the error object with the line number.

 

try {
   // Your whole code here
} catch(err) {
   logger.error(err.message + " in line " + err.lineNumber);
}

 

Top Tags