Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Moro
Contributor
Contributor

Check two entries (excel Sheet) with different types for certain conditions in TMap - ERROR: cannot convert String to double

Hi all!

I am trying to check 2 entries in an excel file to determine what to calculate.

Like the following: If B is TRUE and A is empty then calculation 1, or else condition 2

0695b00000WvqTHAAZ.png 

I tried in TMap:

row2.B !=null && row2.A=="TRUE"? "Blue": "green"

row2.B !=null && row2.A==true? "Blue": "green"

row2.B==true || (row2.A== null || "".equals(row2.A) || row2.A.isEmpty()) ? "Blue": "green"

 

 

I get an alert/Error saying "cant convert .. to string".

OR

Exception in component tMap_1 (filename

java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because "row2.A" is null

 

The following works, when both rows are strings.

row2.Name == null ?"sfd":"sf"

I would like to put a value from another row or calculation with other double type. But then I keep getting errors.

 

Do you have any advice for me how to get to the needed result?

Thank you very much

M

Labels (2)
1 Solution

Accepted Solutions
Anonymous
Not applicable

OK, I think I know why this is happening. Your tMap looks fine apart from one thing. Your expression....

 

row2.A==null && row2.C==true ? "FTL" : "LCL" 

 

....is comparing a null Boolean (class) to a literal boolean. Literal booleans cannot be null, Boolean classes can be. The comparison here is causing the issue. You can correct this with either.....

 

row2.A==null && row2.C != null && row2.C==true ? "FTL" : "LCL" 

 

....or .....

 

row1.A==null && row1.C != null && row1.C.equals(new Boolean(true)) ? "FTL" : "LCL" 

 

I think you are also suffering from a problem which is highlighting this flaw in the code. You show 3 rows in your example above. I suspect that you have used the row below and deleted in the Excel file. This will cause the Excel file to believe it is populated. This will cause it to be read by your job. It will return nulls for all columns.

 

These are largely guesses based on what I have seen. I am sure that the tMap issue needs fixing, but I may be wrong about your Excel file. You may have a row where C is null.

View solution in original post

4 Replies
Anonymous
Not applicable

Can you show your tMap_1 configuration? It looks like you are mixing your column data types.

Moro
Contributor
Contributor
Author

Hi rhall, thanks for you input. I checked the column types and thought they were correct..

This is the input table and then the wished for result table0695b00000Wvrw5AAB.png0695b00000WvrD5AAJ.png

 

 

Exception in component tMap_1 (Copy_of_fillingout_Transpot_TEST)

java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because "row2.C" is null

Anonymous
Not applicable

OK, I think I know why this is happening. Your tMap looks fine apart from one thing. Your expression....

 

row2.A==null && row2.C==true ? "FTL" : "LCL" 

 

....is comparing a null Boolean (class) to a literal boolean. Literal booleans cannot be null, Boolean classes can be. The comparison here is causing the issue. You can correct this with either.....

 

row2.A==null && row2.C != null && row2.C==true ? "FTL" : "LCL" 

 

....or .....

 

row1.A==null && row1.C != null && row1.C.equals(new Boolean(true)) ? "FTL" : "LCL" 

 

I think you are also suffering from a problem which is highlighting this flaw in the code. You show 3 rows in your example above. I suspect that you have used the row below and deleted in the Excel file. This will cause the Excel file to believe it is populated. This will cause it to be read by your job. It will return nulls for all columns.

 

These are largely guesses based on what I have seen. I am sure that the tMap issue needs fixing, but I may be wrong about your Excel file. You may have a row where C is null.

Moro
Contributor
Contributor
Author

It works - thank you very much (for the explanation also!) 🙂