0
每當我打電話給getExcelData()
方法時,我都會收到java.lang.OutOfMemoryError: Java heap space error
。正如你所看到的,我的代碼中也沒有任何循環。但仍面臨問題。獲取java.lang.OutOfMemoryError:以下代碼中的Java堆空間
ExcelLibrary exlb= new ExcelLibrary();
customerId+=exlb.getExcelData("ListCustomer", 1, 0);
而且,類
public class ExcelLibrary {
String filepath;
public ExcelLibrary()
{
filepath="C:\\Users\\Use Me\\Desktop\\Test Data.xlsx";
}
public Sheet getSheet(String sheetName) throws InvalidFormatException, IOException
{
FileInputStream fis= new FileInputStream(filepath);
Workbook wb=WorkbookFactory.create(fis);
Sheet sh=wb.getSheet(sheetName);
return sh;
}
public String getExcelData(String sheetName, int rowNo,int colNo) throws InvalidFormatException, IOException
{
String value="";
Sheet sh=getSheet(sheetName);
Row row=sh.getRow(rowNo);
Cell cell=row.getCell(colNo,Row.CREATE_NULL_AS_BLANK);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC:
value = "NUMERIC value=" + cell.getNumericCellValue();
break;
case Cell.CELL_TYPE_STRING:
value = "STRING value=" + cell.getStringCellValue();
break;
case Cell.CELL_TYPE_FORMULA:
value = "FORMULA value=" + cell.getCellFormula();
break;
case Cell.CELL_TYPE_BLANK:
Reporter.log("No values Exist for the cell",true);
value="";
break;
case Cell.CELL_TYPE_ERROR:
Reporter.log("Cell Value Format Error",true);
value="error";
break;
default:
break;
}
Reporter.log("CELL col=" + cell.getColumnIndex() + " VALUE=" + value, true);
return value;
}
請告訴我測試Data.xlsx的大小,什麼是當前的堆尺寸? –
如何知道堆大小? –
Excel的大小是5.35MB,會影響到我的代碼嗎? –