I am trying to write a NXT Robot simulator with lejOS where the robot can avoid obstacles, but I want the obstacles to be generated in the code. The code below allows for the creation of the Circle.jpg, but the code crashes if it tries to use the image it creates. The code works in Intellij IDEA, but not eclipse with a previously generated image. I have tried the following with no results:
- Used .png instead of .jpg
- Used and image generated by a previous run, meaning it already existed.
- Changed type from opaque to translucent, etc.
I am wondering what I am doing that makes the image crash my code when generating the image on the fly?
Update: Added command used to invoke new jpg, and a picture of the error.
public static void obstacleFactory()
{
int width = 30;
int height = 30;
GraphicsEnvironment environment =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice device =
environment.getDefaultScreenDevice();
GraphicsConfiguration config = device.getDefaultConfiguration();
BufferedImage bufferedImage = config.createCompatibleImage(width, height,
Transparency.TRANSLUCENT);
Graphics2D g2d = bufferedImage.createGraphics();
g2d.setColor(Color.yellow);
g2d.fillOval(0, 0, width, height);
g2d.dispose();
RenderedImage rendImage = bufferedImage;
try {
File file = new File("src/sprites/Circle.jpg");
ImageIO.write(rendImage, "jpg", file);
} catch (IOException e) {}
}
And the command use to invoke the jpg is
NxtContext.useObstacle("sprites/Circle.jpg", 250, 475);
This is what eclipse says: