1
        private static final String[] columns = new String[] {
             "policyID","statecode","county","eq_site_limit","hu_site_limit","fl_site_limit",
             "fr_site_limit","tiv_2011","tiv_2012","eq_site_deductible","hu_site_deductible","fl_site_deductible",
             "fr_site_deductible","point_latitude","point_longitude","line","construction","point_granularity"
        }

        String file = props.getProperty("file");

        ColumnPositionMappingStrategy<Weather> strateg = new ColumnPositionMappingStrategy<Weather>();
        strateg.setType(Weather.class);

        strateg.setColumnMapping(columns);

        CsvToBean<Weather> csv = new CsvToBean<Weather>();
        CSVReader reader = new CSVReader(new FileReader(file),',','\"',1);
        List<Weather> list = csv.parse(strateg, reader);

        for(Object object: list){
            Weather weather = (Weather)object;
            conection.importCsvData(weather);
        }

and the error is this:

 Exception in thread "main" java.lang.RuntimeException: Error parsing CSV line: 1 values: [119736, FL, CLAY COUNTY, 498960, 498960,
 498960, 498960, 498960, 792148.9, 0, 9979.2, 0, 0, 30.102261,
 -81.711777, Residential, Masonry, 1]
            at com.opencsv.bean.CsvToBean.parse(CsvToBean.java:100)
            at com.opencsv.bean.CsvToBean.parse(CsvToBean.java:72)
            at Test.main(Test.java:44)
         Caused by: java.lang.NullPointerException
            at com.opencsv.bean.CsvToBean.processProperty(CsvToBean.java:138)
            at com.opencsv.bean.CsvToBean.processLine(CsvToBean.java:127)
            at com.opencsv.bean.CsvToBean.processLine(CsvToBean.java:106)
            at com.opencsv.bean.CsvToBean.parse(CsvToBean.java:96)
            ... 2 more

I get this error everytime. IF anybody has an idea will be nice! When i had this error last time, it was because i forgot to put a comma between 2 words on columns. If you have any idea please write me as soon as possible. Thank you.

Stewart
  • 17,616
  • 8
  • 52
  • 80
Ollie Pis
  • 13
  • 1
  • 4

1 Answers1

1

The problem is : java.lang.NullPointerException. Solution : go to file CsvToBean.java, at line 138. Check null before you start working with any param.

Incase CsvToBean file inside a library, you need to see which param inside this class got Null. After that, have validate your input data before call this library, if the input is not valid, don't call this class anymore.

BIZ
  • 113
  • 6