0

I am parsing a CSV file using Apache commons CSV using the following code:

CSVFormat csvFileFormat = CSVFormat.EXCEL.withHeader().withQuoteMode(QuoteMode.MINIMAL);

On some of the CSV files I am getting the following error:

java.lang.IllegalArgumentException: 
Mapping for Phone number not found, 
expected one of [Address, City, State, Zip, Phone Number, Product, Comments/Description, Final Status, Date Closed]

I checked the file, it contains a"Phone Number" column, column exist and all the values present.

what am I doing wrong?

3
  • 1
    Export the file from Excel to TEXT (CSV or whatever), then look at the raw data (using Notepad++ perhaps) to see if anything is weird. You could have stray CR/LF characters or stray quotes (only one quote without the finishing quote) or lots of errors in actual CSV format. Excel is renowned for this. If you try to IMPORT that TEXT file into MySQL or SQL Server - it will probably give you a better error with the line number Commented Dec 12, 2017 at 22:06
  • 1
    There is a difference in case, "number" vs "Number" in your question, maybe this is causing problems? Commented Dec 13, 2017 at 6:00
  • this is correct centic, there is a feature on this issues.apache.org/jira/browse/CSV-159 please have this as an answer so i can accept it. Commented Dec 13, 2017 at 14:54

1 Answer 1

1

According to your exception message the n of Phone number is small but the field contains it in Phone Number form. The error will not arrive when it will found a column named in the above message.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.