0

Here's the error I keep getting when trying to run my new method I'm creating.

java.lang.ArrayIndexOutOfBoundsExceptio... Coordinate out of bounds! 
at sun.awt.image.ByteInterleavedRaster.getD... Source) 
at java.awt.image.BufferedImage.getRGB(Unkn... Source) 
at SimplePicture.getBasicPixel(SimplePictur... 
at Pixel.getColor(Pixel.java:184) 
at Picture.rotate(Picture.java:253)` 

Here's the code-

public Picture rotate () { 
    Picture newPic = new Picture(getWidth(),getHeight()); 
    for (int x=0;x<getWidth();x++)  
        for (int y=0;y<getHeight()*2;y++) { 
            Pixel a = getPixel (x,y); 
            Pixel c = getPixel (getWidth()-1-x,y); 
            a.setColor (c.getColor()); 
            c.setColor (a.getColor());
        } 
    return newPic; 
}

Could anyone help?

1
  • There is no compiler error in evidence here, just a runtime exception. Commented Feb 25, 2014 at 2:52

1 Answer 1

2

Did you try not to multiply the height by 2?

for (int y=0;y<getHeight()*2;y++){ 

According to the error message, your coordinates gets out of wack. Ill assume this is because your loop has twice the amount of pixels/iterations as the height - and then ruńs way to many times.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.