java - Supercsv 示例无法编译

标签 java csv supercsv

此示例直接来自 http://super-csv.github.io/super-csv/examples_reading.html 的文档不编译。新 CellProcessor[]{...} 中的所有行都会生成错误“不兼容的类型。必需:CellProcessor Found: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;
    }

}

最佳答案

我刚刚在 IntelliJ 中尝试过此操作,唯一的错误是您缺少 CellProcessor 的导入。

添加

import org.supercsv.cellprocessor.ift.CellProcessor;

一切都应该正常。

关于java - Supercsv 示例无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31735580/

相关文章:

java - For 或 While 循环跳过输入

java - 在 Groovy 中使用参数动态创建方法

python - Pandas 的 read_csv C 引擎有什么方法可以忽略或替换 Unicode 解析错误吗?

php - 从由 CSV 填充的数据库表中填充多个 HTML 表

java - SUPER CSV 将 bean 写入 CSV

带有未转义引号的 Java CSV 解析器

java - 执行校验和时出错

java - 以编程方式访问主类的 MANIFEST.MF

java - 如何对 Azure Web 应用程序使用 XSRF 保护

php excel转mysql问题