提问人:karuna 提问时间:2/8/2020 最后编辑:Ulrich Eckhardtkaruna 更新时间:2/8/2020 访问量:27
在 selenium 中使用 apache poi 读取 Excel 文件,但在尝试在 java 中运行代码时显示 nullpointerException 错误
Using apache poi in selenium for reading Excel file but when trying to run code in java it is showing nullpointerException Error
问:
运行此代码时,它显示nullpointerException错误
线程“main”中的异常 java.lang.NullPointerException 在 npackage。ReadindDataFromExcel.main(ReadindDataFromExcel.java:48)*
public static void main(String[] args) throws Exception
{
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://newtours.demoaut.com");
//Excel File location
FileInputStream file = new FileInputStream("C://Datafirst.xls");
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFSheet sheet = workbook.getSheet("Sheet1");
int noOfRows = sheet.getLastRowNum();
System.out.println("No.of Records in the Excel Sheet:" + noOfRows);
//int colcount=sheet.getRow(0).getLastCellNum();
for (int row = 0; row <= noOfRows; row++)
{
HSSFRow currentrow = sheet.getRow(row);
String First_name = currentrow.getCell(0).getStringCellValue();
}
}
答: 暂无答案
评论