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);
}
,错误是这样的:
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
我每次都会收到此错误。如果有人有想法会很好!当我上次遇到这个错误时,那是因为我忘了在列上的两个单词之间加一个逗号。 如果您有任何想法,请尽快给我写信。 谢谢。
答案 0 :(得分:1)
问题是:java.lang.NullPointerException。 解决方案:转到第138行的文件CsvToBean.java。在开始使用任何参数之前检查null。
在库中包含CsvToBean文件,您需要查看此类中的哪个参数获得Null。之后,在调用此库之前验证输入数据,如果输入无效,则不再调用此类。