0
我在類X
中有一個變量,我想將其內容與另一個類Y
中的字段的值匹配。
我有X
類下面的代碼:將變量中的值與文本字段的值進行比較
String Cellresult;
Cell a1 = sheet.getCell(columNumber,rowNumber); // gets the contents of the cell of a an excell sheet
Cellresult = a1.getContents(); // stores the values in the variable named Cellresult
System.out.println(Cellresult); // prints the values which is working fine till here
現在,在另一個類Y
,我想的Cellresult
值與具有ID txtVFNAME
已經充滿字段的值進行比較。
我想:
WebElement a = idriver.findElement(By.id("txtVFNAME"));
if (a.equals(Cellresult)){
System.out.println("text is equal");
};
我得到的錯誤,甚至在編譯:: Cellresult cannot be resolved to a variable
之前。
我使用java,Eclipse,IE 10,贏得8.kindly幫助。非常感謝。
'Cellresult'只在'X'類中知道,使* getter *在'Y'類中使用。請注意,你的命名非常混亂。我建議您遵循[Java命名約定](http://www.oracle.com/technetwork/java/codeconv-138413.html)。 – Maroun
我如何在另一個課程中訪問它? – newLearner
以及..你的Cellresult是一個局部變量..它不會在函數外部可見..你必須使它成爲類X中的一個實例級別變量(將它放在所有函數之外,但放在類中),添加getter和setter在它的類中,你必須創建一個新的X實例,使用getCellResult()來獲得結果。 – TheLostMind