在selenium中从Excel工作表读取数据时获取空指针异常
我在这段基本代码中遇到了null指针异常。 你可以看到我的excel表格 你能引导我完成这件事吗。 java.lang.NullPointerException在selenium中从Excel工作表读取数据时获取空指针异常,excel,selenium,file-handling,Excel,Selenium,File Handling,我在这段基本代码中遇到了null指针异常。 你可以看到我的excel表格 你能引导我完成这件事吗。 java.lang.NullPointerException 在Work.excelData.main(excelData.java:29)您应该花一些时间学习如何调试简单的脚本。如果你看在页面底部是一个链接。您也可以在您使用的IDE的帮助主题中找到这方面的帮助 package Work; import java.io.FileInputStream; import java.io.FileNo
在Work.excelData.main(excelData.java:29)您应该花一些时间学习如何调试简单的脚本。如果你看在页面底部是一个链接。您也可以在您使用的IDE的帮助主题中找到这方面的帮助
package Work;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.net.NetworkUtils;
public class excelData {
static FileInputStream fis;
static Workbook wb;
public static void main(String[] args) throws EncryptedDocumentException, InvalidFormatException, IOException {
try {
fis = new FileInputStream("C:\\Users\\user\\Desktop\\Selenium.xlsx");
wb = WorkbookFactory.create(fis);
Sheet sh = wb.getSheet("Input");
Row rw = sh.getRow(2);
Cell cs = rw.getCell(2);
String a = cs.getStringCellValue();
System.out.println(cs);
} catch (NullPointerException e) {
e.printStackTrace();
System.out.println("NULL");
}
}
}