How do I resolve errors about incompatible types?
•
Java
I study java projects on IntelliJ Then I found an error about incompatible types in the try catch block This is 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;
Solution
The HSSF workbook class implements the workbook interface
In POI 4 X, the workbook interface implements autoclosable and closable
At POI 3.11 from 3.11 X, the workbook interface only implements closed
(before 3.11, workbooks obviously 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 )
Therefore, if you want to use try with resources to manage HSSF workbook instances, the simple solution is to upgrade to POI 4.0 or later
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码