Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Streamlining user types in Qlik Cloud capacity-based subscriptions: Read the Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Adding integers...

Hi there,
I am newbie, so I'm sorry if the question is so basic 😉
I have an integer context variable called context.nb_lignes
In a tJava composant I would like to increment this variable as follows:
context.InfoGenerale_NB_Lignes = context.InfoGenerale_NB_Lignes + ((Integer)globalMap.get("tSalesforceOutput_2_NB_LINE"));
But Talend crashes again and again with the followingg message.
"Exception in component tJava_1
java.lang.NullPointerException
at parot_digital.jdintegsfc_ent_compte_alim_0_1.JdIntegSfc_ENT_COMPTE_Alim.tMysqlInput_1Process(JdIntegSfc_ENT_COMPTE_Alim.java:6073)
at ..."
Any ideas about what I am doing wrong?

Thanks in advance

Labels (2)
3 Replies
Anonymous
Not applicable
Author

Hello Rubianes,
Check the data type of the context variable you have declared? Is it Integer or String?
Also it is a good idea to initialize the value of the variable before you add another value to it.
So the better way to do it would be as follows:
if (context.InfoGenerale_NB_Lignes == null) {
context.InfoGenerale_NB_Lignes = 0;
}
context.InfoGenerale_NB_Lignes += ((Integer)globalMap.get("tSalesforceOutput_2_NB_LINE"));

Note: if you have declared the variable as String then the values will be concatenated and not added.
Anonymous
Not applicable
Author

Thanks for your answer.
The context variable is an integer initilized (=0) in the context.
With your modification same error! :-((
Any idea?
TRF
Champion II
Champion II

Try 
context.setProperty("InfoGenerale_NB_Lignes", context.InfoGenerale_NB_Lignes + ((Integer)globalMap.get("tSalesforceOutput_2_NB_LINE")))