Return outside method error

From your comment response above, I am going to make the educated guess that you believe that

boolean openingboard;
{
    return true;
}

defines a Java method called openingboard. This isn’t the case. Java follows the C paradigm of requiring you to specify your parameters in parentheses, regardless of whether you have any parameters or not. So, the method

boolean openingboard() {
    return true;
}

is a valid Java method (assuming it is inside some class), as is a version of openingboard with much more code between the curly braces.

That said, I’m going to pass along a few friendly pointers on Java style:

  • Java (and indeed most higher-level language) programmers tend to frown on “forever” loops such as while (true), since those loops make it much harder to determine when the loop actually stops.
  • There is no need for the label search in the code, and labels are even more discouraged than forever loops are.

So, I would recommend rewriting your code to look something like

private boolean openingboard() {
    Robot robot = new Robot();
    Color color3 = new Color(108, 25, 85);
    Rectangle rect = new Rectangle(0, 0, 1365, 770);
    BufferedImage image = robot.createScreenCapture(rect);
    for(int x = 0; x < rectangle.getWidth(); x++) {
        for(int y = 0; y < rectangle.getHeight(); y++) {
            if(image.getRGB(x, y) == color3.getRGB())
                return true;
        }
    }

    return false;
}

assuming of course that you prefer a debugger to trace prints.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)