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