编译像素识别脚本时出现Javac错误
好吧,J Barclay 解决了我的所有问题,除了一个问题!耶!!
无法从静态上下文引用非静态方法 getRGB()。
第 28 行-
新代码-
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GunningBot{
public static void main(String[] args) throws Exception{
Robot robot = new Robot();
Color color = new Color(195, 174, 196);
{
Rectangle rectangle = new Rectangle(0, 0, 1075, 700);
{
BufferedImage image = robot.createScreenCapture(rectangle);
search: for(int x = 0; x < rectangle.getWidth(); x++)
{
for(int y = 0; y < rectangle.getHeight(); y++)
{
if(image.getRGB(x, y) == Color.getRGB())
{
robot.mouseMove(x, y);
break search;
}
}
}
}
}
Well J Barclay cleared up all but one of my problems!! yay!!
non-static method getRGB() cannot be referenced from a static context.
line 28-
new code-
import java.awt.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.AWTException;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class GunningBot{
public static void main(String[] args) throws Exception{
Robot robot = new Robot();
Color color = new Color(195, 174, 196);
{
Rectangle rectangle = new Rectangle(0, 0, 1075, 700);
{
BufferedImage image = robot.createScreenCapture(rectangle);
search: for(int x = 0; x < rectangle.getWidth(); x++)
{
for(int y = 0; y < rectangle.getHeight(); y++)
{
if(image.getRGB(x, y) == Color.getRGB())
{
robot.mouseMove(x, y);
break search;
}
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个问题是您正在访问 Robot 类的实例方法而不是 robots 的实例。
只需更改大小写即可修复:
Color.getRGB(195, 174, 196)
的问题是它是一个 getter,没有参数。调用这个方法的方法是:但是同样,您使用的是没有实例的实例方法,您需要做的是:
The first issue is that you're accessing an instance method on the class Robot instead of an instance of robot.
just change the case and it will be fixed:
The issue with
Color.getRGB(195, 174, 196)
is that it is a getter, it has no parameters. The way to call this method is:but again, you're using accessing an instance method without an instance, what you need to do is: