Results 1 to 2 of 2
  1. #1
    vastrolorde is offline Senior Member
    Join Date
    Jan 2013
    Posts
    124
    Rep Power
    0

    Default arrayoutofbounds

    Java Code:
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;
    import java.awt.Image;
    import java.awt.Color;
    import java.util.ArrayList;
    
    class cypto{
    
    public static void main(String[] args){
    	ArrayList<Integer> roheline;
    	int w;
    	int h;
    	
    	BufferedImage image = null;
    	try{
    		image = ImageIO.read(new File("C://Users//Marko//Desktop//java//hacker.org//greenline.png"));
    	} catch (IOException e) {
        }
    		
    	w = image.getWidth(null);
    	h = image.getHeight(null);
    	roheline = new ArrayList<Integer>();
    	for(int x = 0; x < h; x++){
    		for(int y = 0; y < w; y++){
    			roheline.add(((image.getRGB(x+1, y+1))  >> 8) & 0xff); 
    			}
    			}
    
        //Color c = new Color(dataBuffInt[83]);
    
        //System.out.println(c.getRed());   // = (dataBuffInt[100] >> 16) & 0xFF
        for(int x = 0; x < 83; x ++){
    		System.out.println(roheline.get(x));
    	}
    	// = (dataBuffInt[100] >> 8)  & 0xFF
        //System.out.println(c.getBlue());  // = (dataBuffInt[100] >> 0)  & 0xFF
        //System.out.println(c.getAlpha()); // = (dataBuffInt[100] >> 24) & 0xFF
    
    }
    }
    This line roheline.add(((image.getRGB(x+1, y+1)) >> 8) & 0xff); gives me array out of bounds exception. What to do?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default Re: arrayoutofbounds

    array out of bounds exception. What to do?
    Basically you make sure the indexes used in the code don't go out of bounds.

    What is the size of the image and what are the values of x and y?

    Remember: indexes range in value from 0 to the size-1
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. ArrayoutOfBounds on JTable
    By raffs03 in forum AWT / Swing
    Replies: 10
    Last Post: 03-11-2013, 11:01 PM
  2. Replies: 8
    Last Post: 11-13-2011, 10:51 PM
  3. ArrayOutofBounds Exception
    By aianta in forum New To Java
    Replies: 5
    Last Post: 08-12-2011, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •