2

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.

5
  • What is the installed Java-Version on the other PC? Commented Feb 24, 2020 at 15:30
  • 2
    String.isEmpty() was added in Java 1.6, so the JRE you are running on must be 1.5 or earlier. Commented Feb 24, 2020 at 15:30
  • both pc's have version 1.8.0_91 Commented Feb 24, 2020 at 15:49
  • 1
    isBlank is not available before Java version 11, but I wonder the error message being about isEmpty ?? Commented Feb 24, 2020 at 16:03
  • 1
    I replaced isBlank() with isEmpty && equals(" ") and now it works fine for me. Wrong and correct inputs are identified correctly now. It seems like the isBlank() was what was causing the problem. I stil dont know why i got the java.lang.NoSuchMethodError: java.lang.String.isEmpty()Z error tho. Commented Feb 25, 2020 at 8:54

2 Answers 2

4

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)){
Sign up to request clarification or add additional context in comments.

4 Comments

isBlank() was added in 11 and that's what he is using, not isEmpry()
The other pc's have the same java version. But your suggestion kinda worked for me. BUT: Now, no result is found, instead of "Error", nothing is returned. Do you have an idea why this is the case now, and how I could fix this? :) Thanks for your help so far!
Check if the sentence : XSSFCell cell = row.getCell(colnr); return an object, because based on what you tell me that sentence is returning null. and its a problem about the search in the doc.
It seems like I just needed to replace !CellContent.isBlank(). I replaced it with !CellContent.isEmpty() && !CellContent.equals(" ") and not my return works fine both ways. Thank you very much for putting me in the right direction! :)
0

I also saw this Error with "isBlank()Z". I switched to StringUtils.isBlank(TextVariable).

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.