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

View solution in original post


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

View solution in original post

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 2

Part 2 of a series on Context Variables

Blog

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog