Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve an error about incompatible types?

Tags:

java

try-catch

I work on Intellij about Java project. Then I take an error in my try catch block about incompatible types. Here part of my code:

try (HSSFWorkbook workbook = new HSSFWorkbook(new POIFSFileSystem(new FileInputStream(System.getProperty("user.home") + "D:\\Users\\john\\Desktop\\RBBNCaseManagementTool\\src\\home\\data.xls")))) {

            HSSFSheet filtersheet = workbook.getSheetAt(0);
            int cellnum = filtersheet.getRow(0).getLastCellNum();
            int lastRow = filtersheet.getLastRowNum();
            HSSFCell cellVal1;
            HSSFCell cellVal2;
            HSSFCell cellVal3;

enter image description here Is there any way to solve this error ?

like image 962
Asell Avatar asked Mar 05 '23 22:03

Asell


1 Answers

The HSSFWorkbook class implements the Workbook interface.

In POI 4.x, the Workbook interface implements AutoCloseable and Closeable.

In POI 3.x from 3.11 onwards, the Workbook interface implements onlyCloseable.

(Prior to 3.11, Workbook apparently didn't even implement Closeable; see https://poi.apache.org/changes.html#3.11 and https://bz.apache.org/bugzilla/show_bug.cgi?id=56537)

So, if you want to use try with resources to manage an HSSFWorkbook instance, the simple solution is to upgrade to POI 4.0 or later.

like image 177
Stephen C Avatar answered Mar 15 '23 03:03

Stephen C