【发布时间】:2023-03-23 13:37:02
【问题描述】:
我正在尝试从 Excel 工作表中读取数据,但每次在单元格索引 =6 处读取数据时都会出现 NullPointerException。放置 while(value != null) 以避免空值,但仍然得到没有任何输出的异常。 我正在从我试图获取数据的地方放置 excel 表的屏幕截图。
Code-
package com.selenium;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.IOException;
public class Exxcel {
public static void main(String[] args) throws Exception,NullPointerException{
//WebDriver driver= new FirefoxDriver();
//WebElement wb;
try{
FileInputStream file= new FileInputStream("C:\\Documents and Settings\\OMEGA\\Desktop\\Test Planning And Documents\\Automation Data.xlsx");
Workbook data=WorkbookFactory.create(file);
Sheet sheet=data.getSheet("Sheet1");
for(int i=1;i<=sheet.getLastRowNum();i++){
Row row= sheet.getRow(i);
int j=0;
String value=row.getCell(j).getStringCellValue();
while(value != null){
System.out.println(value);
}//while
while(value == null){
j++;
}
}//for
/*while(j1==9){
String value=row.getCell(j1).getStringCellValue();
System.out.println(value);
}//while2
*/
}catch(NullPointerException n){n.printStackTrace();
System.out.println("Null");
}// catch
}//main
}//class
StackTrace-
Null
java.lang.NullPointerException
at com.selenium.Exxcel.main(Exxcel.java:22)
【问题讨论】:
标签: java vba excel selenium-webdriver