[我试图进入Java机器人类,所以我想起初只是简单地编写一个程序将鼠标移至屏幕上的0,0。
一切看起来都很完美,但是当我尝试运行它时出现错误:
"The method go() is undefined for the type run"
想知道是否有人知道我为什么收到此错误。
main.java:
public class main {
public static void main(String[] args) {
run run = new run();
run.go();
}
}
run.java:
import java.awt.AWTException;
import java.awt.Robot;
public class run {
public void go(){
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
robot.mouseMove(0, 0);
}
}
谢谢
您的类的类型为run
,这就是编译器尝试使用的类型(class
命名 run
),并且没有static void go
。基本上,您有shadowed run
(我注意到它不在包装中,并且类名should以大写字母开头)。我建议您修复这些问题,但您could更改
run run = new run();
run.go();
to
new run().go();