尝试catch java - java抱怨该变量可能无法初始化

时间:2016-08-29 19:24:11

标签: java selenium try-catch

我不太明白为什么java指向"我们"的最后一个实例。下面的代码中的变量,并告诉我它可能没有初始化。初始化发生在第一次尝试catch中。第二个try catch嵌套在第一个try catch下。为什么抱怨?

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;



}

0 个答案:

没有答案