Reputation: 29
public static ArrayList<Double> readSheet(XSSFSheet spreadsheet) {
int rows = spreadsheet.getPhysicalNumberOfRows();
for (int i = 0; i <= i; i++) {
XSSFRow row = spreadsheet.getRow(i);
if (row == null) {
continue;
}
int cells = row.getPhysicalNumberOfCells();
ArrayList<Double> cellList = new ArrayList<>();
for (int j = 0; j < cells; j++) { //遍历每一列
XSSFCell cell = row.getCell(j);
cell.setCellType(cell.CELL_TYPE_STRING);
//new Double("1.0").intValue()
Double cellValue = cell.getNumericCellValue();
cellList.add(cellValue);
}
return cellList;
}
}
Can someone please help
Upvotes: 1
Views: 50
Reputation: 422
Firstly, your condition in for
loop is wrong: i <= i
is always true
.
Secondly, you must provide return statement for all branches. For example, if condition in for
loop will be false
, there is no return
statements in remaining function body.
You should:
cellList
before for
loopreturn
statement outside for
loopUpvotes: 0
Reputation: 1312
You should provide the return statement outside of your for loop:
public static ArrayList<Double> readSheet(XSSFSheet spreadsheet) {
int rows = spreadsheet.getPhysicalNumberOfRows();
ArrayList<Double> cellList = new ArrayList<>();
for (int i = 0; i <= i; i++) {
...
}
return cellList;
}
Because the compile cannot decide if there is any run of your for loop and therefore not guarantee that your return statement will be reached.
This also means that you need to declare your cellList
variable outside of the for loop.
And please also check your loop condition. While i<=i
might be always true
you don't want to loop indefinitely.
Upvotes: 2