调用函数时出现空指针异常

时间:2018-05-17 21:10:03

标签: java nullpointerexception function-call

当我尝试调用函数时,我得到一个空指针异常。我能够在没有问题的情况下在另一个函数中调用此函数,但是当我尝试将其称为第二个函数时,我得到一个空指针。

public class Approvals extends SnowPortalBasePage {

    @Steps
    ApproveNewApplicationSteps tommy;

    private static Logger logger = LogManager.getLogger();

    public void approveNewEnvironment(String envName){
        tommy.logIntoApproverAccount();     <--- throws null pointer
    }

    public void approveNewApplication(RegisterNewApplicationFormData formdata){

        benchmark b = new benchmark();
        tommy.setFormData(formdata);
        b.start("logging into approver account");
        tommy.logIntoApproverAccount();  <--- works
        b.stop();
        b.start("completing data assessment and rationalization task");
        tommy.completeDataAssessmentAndRationalizationTask();
        b.stop();
        b.start();
        tommy.completeTask();
        b.stop();
        logger.info(b.resultsSec());
    }
}

这是带有被调用方法的类

public class ApproveNewApplicationSteps {

    private static Logger logger = LogManager.getLogger();
    private static int MAX_RETRIES = 10;
    SnowPortalBasePage JohnDoe;
    RegisterNewApplicationFormData formData;

    public void logIntoApproverAccount() {
        JohnDoe.getDriver().quit(); // close out the previous webdriver
        JohnDoe.clearBrowserCookies();
        JohnDoe.loginToSNOW(url, "testuser", "password");
        JohnDoe.getDriver().switchTo().defaultContent();
        JohnDoe.openUrl(url);
}

感谢任何帮助。

0 个答案:

没有答案