hey i had started coding in java.I want to display the pixels format of image with the following code but i get errors...Can anyone suggest my code??

public void Pixelvalue(Image img){
     int[] pixelss = new int[w * h];
	PixelGrabber pg = new PixelGrabber(img, 0, 0, w, h, pixelss, 0, w);
	try {
	} catch (InterruptedException e) {
	    System.err.println("interrupted waiting for pixels!");
	if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
	    System.err.println("image fetch aborted or errored");

	    for (int i = 0; i < w; i++) {
		//handlesinglepixel(x+i, y+j, pixels[j * w + i]);
                System.out.println(" pixelss[i]") ;


Uncaught error fetching image:
java.lang.ArrayIndexOutOfBoundsException: 1
at java.awt.image.PixelGrabber.setPixels(PixelGrabber.java:599)
at sun.awt.image.ImageDecoder.setPixels(ImageDecoder.java:120)
at sun.awt.image.JPEGImageDecoder.sendPixels(JPEGImageDecoder.java:97)
at sun.awt.image.JPEGImageDecoder.readImage(Native Method)
at sun.awt.image.JPEGImageDecoder.produceImage(JPEGImageDecoder.java:119)
at sun.awt.image.InputStreamImageSource.doFetch(InputStreamImageSource.java:246)
at sun.awt.image.ImageFetcher.fetchloop(ImageFetcher.java:172)
at sun.awt.image.ImageFetcher.run(ImageFetcher.java:136)
image fetch aborted or errored

w and h look dangerous - suggest you make them local and set them explicitly from the img itself at the start of this method. I'd print them out here as well, just in case.

This article has been dead for over six months. Start a new discussion instead.