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