Skip to main content

java.lang.ArrayIndexOutOfBoundsException: 40

1 reply [Last post]
Joined: 2006-11-10

I got the error message when i try to generate the image using tiledimage.
I already check & print out the array, it works fine.
Can somebody help me how to solve this problem?
Help me, pls...
Thank you very much

import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.lang.*;
import java.lang.String.*;
import javax.swing.*;
import javax.imageio.*;

public class Lossy_Compression {
public static void main(String[] args) {
RenderedImage img;
Raster rasterPic;
boolean stop;
double tempDouble, mse, pnsr;
int[][] jointPixel, conversion;
int[][] tempPix, block;
int widthPic, heightPic, minX, minY, counter, size, convert, destPosX, destPosY;
int tempRow, tempCol;
int[] readPixel, pixels;

img = JAI.create("fileload", "lena512.pgm");
rasterPic = img.getData();
SampleModel sample = rasterPic.getSampleModel();

widthPic = rasterPic.getWidth(); heightPic = rasterPic.getHeight();
minX = rasterPic.getMinX(); minY = rasterPic.getMinY();
counter = 0; destPosX = 0; destPosY = 0;

size = widthPic * heightPic;

tempPix = new int[heightPic][widthPic];
block = new int[8][8];
jointPixel = new int[40][40];
pixels = new int[size];
conversion = new int[8][8];

PixelAccessor pixAcc = new PixelAccessor(img);
UnpackedImageData pix = pixAcc.getPixels(rasterPic, rasterPic.getBounds(), DataBuffer.TYPE_INT, false);
tempPix = pix.getIntData();

int[][] myPix = new int[widthPic][heightPic];
for(int i=0; i

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2004-06-23

The posted code does not compile: incompatible types
found : int
required: int[]
myPix[j] = tempPix[0][counter++];
^ operator + cannot be applied to int,int[]
convert = convert + block[a];
^ incompatible types
found : int
required: int[]
conversion[j] = convert;
^ incompatible types
found : int[]
required: int
jointPixel[destPosY][destPosX] = conversion[j];
4 errors