Supercsv示例没有编译

时间:2015-07-30 23:10:04

标签: java csv supercsv

这个例子直接来自http://super-csv.github.io/super-csv/examples_reading.html的文档,并没有编译。新CellProcessor [] {...}中的所有行都会生成错误"不兼容的类型。必需:找到CellProcessor:org.supercsv.cellprocessor.constraint.UniqueHashCode"

我错过了什么?

import org.supercsv.cellprocessor.Optional;
import org.supercsv.cellprocessor.ParseBool;
import org.supercsv.cellprocessor.ParseDate;
import org.supercsv.cellprocessor.ParseInt;
import org.supercsv.cellprocessor.constraint.LMinMax;
import org.supercsv.cellprocessor.constraint.NotNull;
import org.supercsv.cellprocessor.constraint.StrRegEx;
import org.supercsv.cellprocessor.constraint.UniqueHashCode;

public class Foo {


    private static CellProcessor[] getProcessors() {

        final String emailRegex = "[a-z0-9\\._]+@[a-z0-9\\.]+"; // just an example, not very robust!
        StrRegEx.registerMessage(emailRegex, "must be a valid email address");

        final CellProcessor[] processors = new CellProcessor[] {
                new UniqueHashCode(), // customerNo (must be unique)
                new NotNull(), // firstName
                new NotNull(), // lastName
                new ParseDate("dd/MM/yyyy"), // birthDate
                new NotNull(), // mailingAddress
                new Optional(new ParseBool()), // married
                new Optional(new ParseInt()), // numberOfKids
                new NotNull(), // favouriteQuote
                new StrRegEx(emailRegex), // email
                new LMinMax(0L, LMinMax.MAX_LONG) // loyaltyPoints
        };

        return processors;
    }

}

1 个答案:

答案 0 :(得分:1)

我刚刚在IntelliJ中试过这个,唯一不对的是你错过了CellProcessor的导入。

添加

import org.supercsv.cellprocessor.ift.CellProcessor;

一切都应该有效。