title: No header mapping was specified, the record values can't be accessed by name (Apache Commons CSV)
body: <p>I got this error message happening when I'm trying to read a csv:</p>
  
  <pre><code>Exception in thread "main" java.lang.IllegalStateException: No header mapping was specified, the record values can't be accessed by name
  at org.apache.commons.csv.CSVRecord.get(CSVRecord.java:99)
  at mockdata.MockData.main(MockData.java:33)
  </code></pre>
  
  <p>Java Result: 1</p>
  
  <p>I'm using Apache Commons CSV library 1.1. Tried googling the error message and the only thing I get is the code listing on sites like grepcode.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>package mockdata;
  
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.Reader;
  import org.apache.commons.csv.CSVFormat;
  import org.apache.commons.csv.CSVRecord;
  
  public class MockData
  {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) throws FileNotFoundException, IOException
      {
          Reader in = new InputStreamReader(MockData.class.getClassLoader()
                                  .getResourceAsStream("MOCK_DATA.csv"), "UTF-8");
          Iterable&lt;CSVRecord&gt; records = CSVFormat.EXCEL.parse(in);
          for (CSVRecord record : records) 
          {
              String lastName = record.get("last_name");
              String firstName = record.get("first_name");
  
              System.out.println("firstName: " + firstName + " lastName: " + lastName);
          }
      }
  
  }
  </code></pre>
  
  <p>The contents of CSV:</p>
  
  <pre><code>first_name,last_name,address1,city,state,zip,country,phone,email
  Robin,Lee,668 Kinsman Road,Hagerstown,TX,94913,United States,5-(078)623-0713,rlee0@e-recht24.de
  Bobby,Moreno,68 Dorton Avenue,Reno,AZ,79934,United States,5-(080)410-6743,bmoreno1@ihg.com
  Eugene,Alexander,3 Bunker Hill Court,Newark,MS,30066,United States,5-(822)147-6867,ealexander2@gmpg.org
  Katherine,Crawford,3557 Caliangt Avenue,New Orleans,OR,23289,United States,2-(686)178-7222,kcrawford3@symantec.com
  </code></pre>
  
  <p>It's located in my src folder.</p>