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

16,403

Solution 1

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

Solution 2

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>
Share:
16,403
Ravi
Author by

Ravi

Updated on September 16, 2022

Comments

  • Ravi
    Ravi over 1 year
    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?

    • Axel Richter
      Axel Richter over 4 years
      The org.apache.poi.util.POILogger was an abstract class until apache poi 4.0.1. Now in apache poi 4.1.0 it is an interface. You have a mix of apache poi versions running. Exactly version 4.1.0 and an earlier version. Don't do that.
    • dadoonet
      dadoonet over 4 years
      Hey Alex Ritcher. Would you like to add your comment as the answer? It also solves my issue and I'd love to "vote" for your answer :)
    • Sandeepa
      Sandeepa over 4 years
      I'm using 4.1.1 version and it's an interface in that version as well. How can I get rid of the exception instead of lowering the version to 4.0.1?
  • Tarit Ray
    Tarit Ray over 3 years
    <!-- mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <!-- mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> I have used still same error !!!
  • Tarit Ray
    Tarit Ray over 3 years
    <!-- mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>4.1.2</version> </dependency> <!-- mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> </dependency> I have used still same error !!!
  • user1169587
    user1169587 about 3 years
    @TaritRay I also use 4.1.2 and has error...how you solve finally?