0

I don't quite understand why java is pointing to the last instance of the "we" variable in the code below and telling me that it might not be initialized. The initialization happens in the first try catch. The second try catch is nested under the first try catch. Why is it complaining?

public void runTests() {

int testIndex;
WebElement we;

//Test 1 - Unchecking County Lines
testIndex=1;
if (testTest[testIndex]) {
    printTestStart(testIndex);

    //FIRST TEST:
    try {

        //* MAIN TEST LOGIC GOES HERE **************************
        we = driver.findElement(By.id("chkCounties"));
        we.click();
        //* MAIN TEST LOGIC GOES HERE **************************
        this.testPassed[testIndex] = this.getPassFail(testIndex);

    } catch (Exception e) {
        testPassed[testIndex] = false;
    }

    //DEPENDANT TEST:
    testIndex +=1;
    if (testPassed[testIndex-1] && testTest[testIndex]) {

        try {
            //* MAIN TEST LOGIC (Dependant Test) GOES HERE *********
            we.click();
            //* MAIN TEST LOGIC (Dependant Test) GOES HERE *********
            this.testPassed[testIndex] = this.getPassFail(testIndex);

        } catch (Exception ee) {
            testPassed[testIndex] = false;
        }

    }
}


testIndex=3;



}
Sir Fartsalot
  • 125
  • 2
  • 12
  • ANSWER: default we to null (on declaration) and problem solved. – Sir Fartsalot Aug 31 '16 at 19:18
  • ANSWER: (above comment answers question) THIS IS NOT DUPLICATE. Variable is initialized in the first try, so it shouldn't be complaining like that. The workaround is to null it out in the declaration.... – Sir Fartsalot Aug 31 '16 at 20:59

0 Answers0