Pointers 空指针异常即将出现

Pointers 空指针异常即将出现,pointers,exception,null,Pointers,Exception,Null,我得到上述代码的空指针异常 这很正常。您已经声明了webdriver变量,但根本没有初始化它。尝试初始化它或从某处获取它,使其不能为null public static WebDriver getscreenshot(String path) throws Exception { WebDriver driver = null; TakesScreenshot ts = (TakesScreenshot)driver; File scrFile = ts.getScre

我得到上述代码的空指针异常

这很正常。您已经声明了webdriver变量,但根本没有初始化它。尝试初始化它或从某处获取它,使其不能为null

public static WebDriver getscreenshot(String path) throws Exception 
{
    WebDriver driver = null;
    TakesScreenshot ts = (TakesScreenshot)driver;
    File scrFile = ts.getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File(path));
    return driver;
}
WebDriver driver = new WebDriver(some parameters here if any);