找到接口org.apache.poi.util.POILogger,但是类是预期的错误

时间:2019-09-28 15:14:09

标签: java maven selenium-webdriver apache-poi

public String readExcel(String columnname,String UserType) {


        try {
            FileInputStream file = new FileInputStream(path);
            @SuppressWarnings("resource")
            XSSFWorkbook wr = new XSSFWorkbook(file);
            XSSFSheet sh = wr.getSheet(prop.getProperty("env"));
            int row = sh.getPhysicalNumberOfRows();
            System.out.println(row);

                for(int j=0;j<row;j++) {
                    if((sh.getRow(j).getCell(1).getStringCellValue()).equalsIgnoreCase(UserType)) {
                        for(int i=0;i<row;i++) {
                            String s=sh.getRow(0).getCell(i).getStringCellValue();
                            if(s.equals(columnname)) {
                                 value = sh.getRow(0).getCell(i).getStringCellValue();
                            }
                        }
                    }
                }
            }catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
        return value;
    }
    public static void main(String args[]) {
        Util obj=new Util();
        obj.readExcel("Username","Testuser1");
    }

我正在使用此代码从Excel读取数据,但在线程“主” java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected中遇到异常。 不确定原因,有人可以帮我吗?

2 个答案:

答案 0 :(得分:5)

将此添加到您的pom.xml文件中

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>x.x.x</version>
</dependency>

poi-ooxml poi 的版本应该相同。

我假设您的pom.xml文件中已经有 poi

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>x.x.x</version>
</dependency>

希望这会有所帮助

答案 1 :(得分:1)

poipoi-ooxml的版本不匹配时出现此错误。这导致了错误:

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>4.1.2</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.15</version>
</dependency>

对齐这些库的版本后,错误消失了

<properties>
    <poi.version>4.1.2</poi.version>
</properties>

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>${poi.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>${poi.version}</version>
</dependency>