Note that there are some explanatory texts on larger screens.

plurals
  1. POException in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 in AWT
    primarykey
    data
    text
    <p>This is the code I have now, it compiles fine but gives me the above error when I try to run it.</p> <pre><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 color1 = new Color(195, 174, 196); { Rectangle rectangle = new Rectangle(0, 0, 1075, 700); { BufferedImage image = robot.createScreenCapture(rectangle); search: for (int x = 0; x &lt; rectangle.getWidth(); x++) { for (int y = 0; y &lt; rectangle.getHeight(); y++) { if (image.getRGB(x, y) == color1.getRGB()) { robot.mouseMove(x, y); break search; } } } } } robot.delay(0); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(0); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(15); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(0); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(1500); robot.mouseMove(510, 440); //DO THIS BOTTOM LEFT robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(500, 140); //MOVE TO LEFT 5 PXLS robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(250); robot.mouseMove(500, 370); //DO THIS TOP RIGHT robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(510, 370); //MOVE TO RIGHT 5 PXLS robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(250); robot.mouseMove(700, 440); //DO THIS RIGHT CORNER MOVE LEFT 5 robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(690, 440); //MOVE TO LEFT 5 PXLS robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(250); robot.mouseMove(315, 370); //DO THIS LEFT CORNER MOVE RIGHT 5 robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseMove(320, 370); //MOVE TO RIGHT 5 PXLS robot.mouseRelease(InputEvent.BUTTON1_MASK); } } </code></pre> <p>I have found many example fixes that go on about over extending the Array and so on but I don't use an array. So I do not understand how to fix this error for this script. Any help at all would be amazing.</p> <p>The full error is:</p> <blockquote> <p>exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at GunningBot.main(GunningBot.java:39)</p> </blockquote> <p>bufferimage uses a Raster, could this be the problem? rectangle is just setting the rectangle of the screen to get a screenshot of.</p> <p>Also I'm editing the code with Notepad++ and don't know how to set an exception without eclipse.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload