在Apache的POI空指针异常 [英] Null Pointer Exception in Apache poi
问题描述
FileInputStream input=new FileInputStream(new File("TestCase.xls"));
HSSFWorkbook workbook=new HSSFWorkbook(input);
HSSFSheet sheet=workbook.getSheet("KeywordFramework");
System.out.println("i am in");
int rowNum = sheet.getLastRowNum() + 1;
System.out.println(rowNum);
int colNum = sheet.getRow(0).getLastCellNum();
System.out.println(colNum);
String data [][] = new String[rowNum][colNum];
for(int i =1 ; i< rowNum;i++)
{
System.out.println("1");
HSSFRow row = sheet.getRow(i);
for(int j = 0; j< colNum;j++)
{
System.out.println("2");
HSSFCell cell = row.getCell(j);
String Cellvalue = cellToString(cell);
System.out.println("cellvalue === "+Cellvalue);
switch(j)
{
case 0 : Function ; break;
case 1 : Function ; break;
case n : Function(has 2 nested for loops) ; break;
} // for switch
Function;
} // for j loop } // for i loop
空指针异常发现,我已要求小区之一的情况下,n和刹车了,但仍然是相同的值从Excel中再次呼吁,并试图把该单元格的值在我的code和不能这样做,因为没有更多的情况下,我不希望我的code到同一行中再次调用Excel单元格,就应该跳出循环,执行下一行未发生
Null pointer exception Found , i have called one of a cell in case n and braked out but still the same value is called again from the excel and is trying to place that cell value in my code and is not able to do so as there is no more cases , i dont want my code to call the excel cell again in the same row , it should jump out of loop and execute the next row which is not happening
感谢您
推荐答案
您的问题是不明确的,如果你想遍历所有的元素的高度,这将是
Your question isn't clear, if you want to loop over the height of the element that would be
for(int a=0;a<SOT.getHeight();a++)
或宽度,
for(int a=0;a<SOT.getWidth();a++)
从的Javadoc 尺寸
Dimension类封装组件的单个对象的宽度和高度(整数precision)。
The Dimension class encapsulates the width and height of a component (in integer precision) in a single object.
这篇关于在Apache的POI空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!