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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tXMLMAP: expressions and java.lang.NullPointerException

Hello,
I have the following expression in tXMLMAP component.
Although I check every variable before to use it in the calcul, I have a java.lang.NullPointerException 
What is wrong with my expression?
Thanks in advance.
!= null && != null && != null && !=null && .equals("POD")? 
(Float.valueOf()+Float.valueOf()-Float.valueOf() )/1000 :
!= null && != null && !=null && .equals("JSF")? 
(Float.valueOf()+Float.valueOf())/1000 : null 
0683p000009MDgV.png
Labels (4)
18 Replies
Anonymous
Not applicable
Author

OK, this is good news. I can't see all of the data types in your screen shot, but I can see enough to assume that maybe the datatype for the fields that "!=null" doesn't work for are maybe "String". To get round this, try something like .....
.trim().compareToIgnoreCase("")!=0 
.....as well as !=null
If it is this, then maybe it might be a bit neater to write a Routine to do this checking for you. So you could have a Routine with a method called "checkNotEmpty(String column)" (or similar) and use that to tidy up your expressions.
Anonymous
Not applicable
Author

With the solution that you suggest I have always an error.
The variables used in the expression are coming diredtly from the XML file:
all_tmp.DDPT = treeNodeAPI_tXMLMap_1_TXMLMAP_OUT
.get_String(
"row1.METRO:/METRO/METROLOGIE/T2_T0")
.trim().compareToIgnoreCase("") != 0
&& treeNodeAPI_tXMLMap_1_TXMLMAP_OUT
.get_String(
"row1.METRO:/METRO/METROLOGIE/T1_T3")
.trim()
.compareToIgnoreCase("") != 0
Anonymous
Not applicable
Author

Hmmmm I think you *may* have stumbled upon a *feature* 🙂 
I decided to rebuild your job using the XML you supplied to see what was happening and found a way around this. I couldn't see anything wrong with your expression, so re-worked it using the tXMLMap variables. I created two Float variables (making sure that the Nullable box was ticked). The expression for the first variable (Var.Var1) was set to .....

!= null && != null && != null && !=null && .equals("POD")? 
(Float.valueOf()+Float.valueOf()-Float.valueOf() )/1000 : null


The expression for the second variable (Var.Var2) was set to .....
!= null && != null && !=null && .equals("JSF")? 
(Float.valueOf()+Float.valueOf())/1000 : null 

I then used the variables in the expression for the output value like below...
Var.Var1!=null ? Var.Var1 : Var.Var2!=null ? Var.Var2 : null 

This worked. I would raise this issue with Talend support if you have the Enterprise Edition
Anonymous
Not applicable
Author

Hello,
No, we don't have the Enterprise Edition but you can raise it as bug, no?
I tried to do it like what you described above, it couldn't find var1 and var2.
what's wrong?
0683p000009MDgu.png 0683p000009MDgz.png 0683p000009MDKV.png 0683p000009MDh4.png
Anonymous
Not applicable
Author

You need to create the Var1 and Var2 variables. They were tMap variables that I created for the example. The variables section is between the input and output sections of the tMap config display.
Anonymous
Not applicable
Author

I created var1 and var2 in the tXMLMAP iteself and used them in the same component, is that possible?
Or I have to add a new tMAP after tXMLMAp to calculate the variable var based on var1 and var2?
Anonymous
Not applicable
Author

Yes, that is right. When I said tMap, I meant tXMLMap. Create the variables in the tXMLMap and assign them values using the expressions described in my solution. Then use .....
Var.Var1!=null ? Var.Var1 : Var.Var2!=null ? Var.Var2 : null 

... in your output column.
Anonymous
Not applicable
Author

Thanks it works!
But I think that it is not normal to be unable to make expressions with if elseif else in the tXMLMAP directly.
we have to make them in two steps!
It deserves to  raise the issue to talend developpement team.
Anonymous
Not applicable
Author

I agree. I have only seen this issue in your example though. I use inline IFs a lot in my tMap/tXMLMap components. I suspect that it is something to do with processing an XML  entity in a single expression more than once. It looks like the first time the entity is checked (or used) it is fine, but the second time it is null.
I should probably point out that I no longer work for Talend and have my own business working with Talend tools. My user on here still shows as a "Talend User" and I am looking to get that changed. If I find the cause of this issue I will pass it on to the guys at Talend.