[resolved] Convert a string to integer

One Star

[resolved] Convert a string to integer

I want to  convert a string field to Integer variable:
(Integer)globalMap.put("BillCount", Integer.parseInt(Trailer.TotalRecCount)))
I got error:java.lang.NullPointerException:null.
I am sure Trailer.TotalRecCount is a existing field in my tMap and is not an empty string. What is wrong in my code?
Another similar conversion that convert a string to double variable is working good.
((Double)globalMap.put("BillTotall", Double.parseDouble(Trailer.TotalAmount))).   
Please help.

Accepted Solutions
Seventeen Stars

Re: [resolved] Convert a string to integer

The put method only returns a value if there was a previous value in the map with the same key. If you add a complete new value to the globalMap the put method returns null.
You should simplify your code like this:
globalMap.put("BillCount", Integer.parseInt(Trailer.TotalRecCount))

All Replies
Seventeen Stars

Re: [resolved] Convert a string to integer

The put method only returns a value if there was a previous value in the map with the same key. If you add a complete new value to the globalMap the put method returns null.
You should simplify your code like this:
globalMap.put("BillCount", Integer.parseInt(Trailer.TotalRecCount))

What’s New for Talend Spring ’19

Watch the recorded webinar!

Watch Now

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download