有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java找到了接口组织。阿帕奇。波伊。util。POILogger,但类应为错误

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中读取数据,但在线程“main”java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected中出现异常。 不确定原因,有人能帮我吗


共 (1) 个答案

  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>