[resolved] Convert a string to integer

Highlighted
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))

15TH OCTOBER, COUNTY HALL, LONDON

Join us at the Community Lounge.

Register Now

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Why Companies Move to the Cloud: 7 Success Stories

Learn how and why companies are moving to the Cloud

Read Now