How to debug a NumberFormatException

I have a datamapper to handle XML input. When I either use the datamapper in a workflow or import some data files into Designer I get a NumberFormatException error.

The error message is indicating that the exception is in a repeating extract. Most of the fields in this extract are strings however there are three currency fields. I’ve had look at the data and there doesn’t seem to be anything obviously invalid. (ie. all the values are numeric).

What should I be looking at to isolate what the problem is?

It maybe caused by an empty value or simply a 0.

Maybe it’s better you extract strings and convert to currency values afterwards. That way you would have full control and could check before if the value is a valid currency.

First thing, recall that when you tell the DataMapper that an extract is to be formatted as a “Currency” you also have to give it a mask so it can identify the number it’s looking at.

If you’ve told it that it should look for Negative Sign Before, Decimal Separator of period (.), thosands seperator of comma (,) and currency sign of USD ($) it will only accept a value formatted that way.

So consider the following.

$1,000.00 is a valid currency according to my criteria above
1,000.00 is not. Nor is 1000,00

To begin troubleshooting, you’re going to want to load that data sample into your datamapper in Design. Set the Record limit in the boundaries to include all of the records in this set (default of 200, so if you have 1000 records, you’ll need to bump it up). Finally, run a data validation (Alt + V or click the green check in the toolbar).

This should tell you if there are any errors in the data and at which record. Go to the first record in the set and check to see how the currency value is written there. If it doesn’t match the expected format, you’re going to have to do some work to normalize the format in the data via a scripted extract.

Thank you both for your suggestions. AlbertsN’s troubleshooting tip was very helpful.

I tried to validate the sample and this gave me an indication of a few fields that could have been causing the problem. I changed all of these to strings and the sample then validated correctly. I then changed them back to currency one-by-one and isolated the problem field (which was blank). I checked the “treat blank as 0” and this seems to have resolved the problem.

Good stuff! Glad to hear it helped :smiley: