Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Found interface org.apache.poi.util.POILogger, but class was expected error

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");
    }

I am using this code to read data from Excel, but getting an exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface org.apache.poi.util.POILogger, but class was expected. Not sure about the reason, can anyone help me with this, please?

like image 261
Ravi Avatar asked Sep 28 '19 15:09

Ravi


2 Answers

Add this in your pom.xml file

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

The version of poi-ooxml and poi should be the same.

I am assuming that you already have poi in your pom.xml file

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

Hope this helps

like image 191
Fonji Fonkeng Rocard Avatar answered Oct 28 '22 16:10

Fonji Fonkeng Rocard


I got this error when the versions of poi and poi-ooxml did not match. This caused the error:

<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>

The error went away after aligning the versions of these libraries:

<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>
like image 29
gil.fernandes Avatar answered Oct 28 '22 17:10

gil.fernandes