First, sorry for basic questions..But still, I could not run the run properly. The whole code is like this, and I run it with eclipse.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.poifs.filesystem.*;
import org.apache.poi.hssf.usermodel.*;
public class hannimpeha1 {
public static void main(String[] args) throws IOException {
// Locate xls file.
File workbookfile = new File("C:\\Users\\bok\\Desktop\\old.xls");
FileInputStream file = new FileInputStream(workbookfile);
POIFSFileSystem fs = new POIFSFileSystem(file);
@SuppressWarnings("resource")
HSSFSheet sheet = new HSSFWorkbook(fs).getSheetAt(1);
// Get row and column count.
int rowCount = sheet.getPhysicalNumberOfRows();
int colCount = sheet.getRow(0).getLastCellNum();
// Iterate over rows and columns.
for(int r = 0; r < rowCount; r++) {
HSSFRow row = sheet.getRow(r);
for(int c = 0; c < colCount; c++) {
HSSFCell cell = row.getCell(c);
String cellval = cell.toString();
System.out.print(" | " + cellval);
}
System.out.println(" |");
}
}
}
The code itself seems okay, but it throws out,
"Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections4/ListValuedMap
at hannimpeha1.main(hannimpeha1.java:15)"
if I put XSSFRow row = null;
to suppress error message, otherwise I got The local variable row may not have been initialized
what is this mean? and how can I fix this? Thank you for your suggestions.