gpt4 book ai didi

java - 机器人r无法解析

转载 作者:行者123 更新时间:2023-12-01 08:03:41 24 4
gpt4 key购买 nike

public void method1 (int x) {
if (x == 1) {
try {
Robot r = new Robot();
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
r.mouseMove(50,50);

但这使得r无法解析。有任何想法吗? =/非常感谢

最佳答案

public void method1 (int x) {
if (x == 1) {
try {
Robot r = new Robot(); // R is defined in the try block. It is not visible outside of this block.
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
r.mouseMove(50,50); // R is not defined anymore here

替换为

public void method1 (int x) {
if (x == 1) {
try {
Robot r = new Robot();
r.mouseMove(50,50);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

关于java - 机器人r无法解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23289719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com