Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
citrods
Contributor
Contributor

Simple case with a column which contains Double : I dont understand this error with java.lang.NullPointerException

Hello

I have a very simple transformation with a tMap which deals with a column with has Double.

My input file is simple :

0695b00000EZMJzAAP.png 

In my output file, I want to fill in the 2 column with 1.5 if the type of room is related to "group A"

I use a tMap :

0695b00000EZMHjAAP.png 

My tMap is set as such:

0695b00000EZMLRAA5.png 

When i run the job , I have a message error with java.lang.NullPointerException.

 

however, if my second column "area" is set a String instead of a double and in the tmap I write

row1.group.equals("Group A")? "1.5": row1.area

Then it works perfectly.

However I need a double as I will later perform some mathematical operations later.

can you explain why i doesn't work with a double?

Labels (2)
1 Solution

Accepted Solutions
gjeremy1617088143
Creator III
Creator III

after few search you could use this : "Group A".equals(row1.group)? new Double(1.5): row1.area.

 

If any of the operands is of a reference type, unboxing conversion is performed. Then: If either operand is of type double, the other is converted to double instead of Double

 

View solution in original post

6 Replies
gjeremy1617088143
Creator III
Creator III

HI, I reproduce your error , it's because row1.area can be null when group not equals Group A and ternary in the Tmap seems to don't work with nullable Double( this is weird cause Double like Integer support nullable values) . To bypass this I make a custom routine :

package routines;

 

public class Double_routine {

 

 

   public static Double check(String group,Double area ) {

       if ("Group A".equals(group)) {

          return 1.5;

       }

       return area;

 

   }

}

 

 

and in the Tmap I call it : Double_routine.check(row1.group,row1.area)

and it's work !

Send me Love and Kudos

gjeremy1617088143
Creator III
Creator III

after few search you could use this : "Group A".equals(row1.group)? new Double(1.5): row1.area.

 

If any of the operands is of a reference type, unboxing conversion is performed. Then: If either operand is of type double, the other is converted to double instead of Double

 

citrods
Contributor
Contributor
Author

hello

i'm a beginner. What do you mean by custom routine and package routines?

can I have a screenshot of the job you made?

 

Also i dudn't get your 2nd message

"if any of the operands is of a reference type, unboxing conversion is performed. Then: If either operand is of type double, the other is converted to double instead of Double"

what is an unboxing conversion?

what is the difference between double and Double?

gjeremy1617088143
Creator III
Creator III

Hi, double is a primitive java type and Double is a wrapper of double, so double is not nullable, Double is nullable.when you write 1.5 in your ternary it read it as a double and so it read row1.area as a double( it’ a consequence of the ternary autoboxing) , some values of area are null then it throw a null pointer exception. To avoid this you have to write new Double(1.5) then row1.area will be interpreted as a Double in the ternary expression and output will accept null value. An other way to avoid that is to write a simple routine with Double as return Value( the full code of the routine is in the first sentence). A routine in talend is similar to a java class. You can find them on the repository view —> Code—> Routines. You can write your own by the way. Send me Love and Kudos

gjeremy1617088143
Creator III
Creator III

Hi, if my answer is ok , could you select it as the best please

citrods
Contributor
Contributor
Author

ok