说明问题:
我想截图并存储在ScreenShoot项目文件夹中,并使用(.png)格式保存日期格式。但是抛出错误,空指针异常。 以下代码抛出NULLPoINTEREXCEPTION :
public String takeScreenShot() {
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
new File(ScreenShot).mkdirs(); // Create folder under project with name
// "screenshots" if doesn't exist
destFile = dateFormat.format(new Date()) + ".png"; // Set file name
// using current
// date time.
try {
FileUtils.copyFile(scrFile, new File(ScreenShot + "/" + destFile)); // Copy
// paste
// file
// at
// destination
// folder
// location
} catch (IOException e) {
System.out.println("Image not transfered to screenshot folder");
e.printStackTrace();
}
return destFile;
}
错误日志:
线程“ main”中的异常java.lang.NullPointerException
Generic.ReadToastMessage.takeScreenShot