最小可重现示例:
int value=scan.nextInt();
String S1=scan.nextInt();
if(value==2)
String S2=scan.nextLine();
//some lines of code
if(value==2)
driver.findElement(By.id("id2")).sendKeys(S2);
由于以下行,我收到“S2 无法解析为变量”:
driver.findElement(By.id("id2")).sendKeys(S2);
最佳答案
在此代码中
if(value==2)
String S2=scan.nextLine();
变量S2
立即超出范围。
尝试
String S2 = "";
if(value==2)
S2=scan.nextLine();
关于java - if语句中字符串扫描时出现 "String cannot be resolved to a variable"如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57653141/