Search code examples
javaexcelapache-poinosuchmethod

java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z


I have encountered the error:

java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z

The installed java version on my pc is 1.8.0_91.

The funny thing is, that this error does not occur on my pc, but on other pc's I tried to run my program. The error seems to be connected to a line from a class who looks up info from an excel-sheet via apache poi 4.1.1.

The troubling line of code is this one: if(!CellContent.isBlank()){ the complete class looks like this:

public class TrueExcelFind {



    XSSFSheet sheet;

    public TrueExcelFind() {

        try{

        String fileName = "C:/Temp/exceltest.xlsx";

        InputStream input = new FileInputStream(fileName);

        XSSFWorkbook wb = new XSSFWorkbook(input);
        sheet = wb.getSheetAt(0);

        } catch(FileNotFoundException ex) {
            System.err.println("File not found " + ex);
        } catch(IOException ex){
            System.err.println("Unable to load " + ex);
        }

    }

        private static int findRow(XSSFSheet sheet, String cellContent) {
            for (Row row : sheet) {
                for (Cell cell : row) {
                    if (cell.getCellType() == CellType.STRING) {
                        if (cell.getRichStringCellValue().getString().trim().equals(cellContent)) {
                            return row.getRowNum();  
                        }
                    }

                    if (cell.getCellType().equals(CellType.NUMERIC)){
                        if (DateUtil.isCellDateFormatted(cell)) {
                            System.out.println(cell.getDateCellValue());

                        } else {
                            int lookup = (int) cell.getNumericCellValue();
                            String catcher = Integer.toString(lookup);

                            if(catcher.equals(cellContent)){
                                return row.getRowNum();
                            }
                        }

                    }

                }
            }               
            return 0;
        }

        public String getVaule(String suchobjekt, String ID){

            int colnr;
            int rownr;

            switch (suchobjekt) {
                case "Karton":
                    colnr = 10; 
                    break;
                case "Palette":
                    colnr = 11; 
                    break;
                default:
                    String ERROR = "ERROR, no such search-term";
                    return ERROR;
            }

            rownr = findRow(sheet, ID);

            XSSFRow row = sheet.getRow(rownr);
            XSSFCell cell = row.getCell(colnr);


            String CellContent = ""+cell;

            if(!CellContent.isBlank()){

                System.out.println("Outcome: "+row.getCell(colnr));
                return CellContent;

            } else {
                CellContent = "ERROR";
                System.out.println("Outcome: ERROR");
                return CellContent;   
            }


        }

}

What my program does: I an other class, I am trying to read the input from a text field and check if the class TrueExcelFind can find a matching result. If so, print out a specific answer.

My guess is that the error may have something to to with the poi libraries. The libraries are included in the executable .jar.

Does anyone have an idea what is wrong here? I am stuck at this point and don't know what to do.


Solution

  • The isEmpty function is enabled since 1.6 java version, maybe in the other pc there is a java 5 installed.

    Try to run a java -version in that pc to discard that.

    And remeber you can always use native validation like replacing your condition to run in older versions :

    if(!CellContent.isBlank()){
    

    for

     if(CellContent !=null || !"".equals(CellContent)){