Skip to main content

java.lang.ArrayIndexOutOfBoundsException: 40

1 reply [Last post]
cemplukcute2003
Offline
Joined: 2006-11-10
Points: 0

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

[code]
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.image.*;
import java.lang.*;
import java.lang.String.*;
import javax.swing.*;
import javax.imageio.*;
import javax.media.jai.*;

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.
bpb
Offline
Joined: 2004-06-23
Points: 0

The posted code does not compile:

Lossy_Compression.java:46: incompatible types
found : int
required: int[]
myPix[j] = tempPix[0][counter++];
^
Lossy_Compression.java:66: operator + cannot be applied to int,int[]
convert = convert + block[a];
^
Lossy_Compression.java:74: incompatible types
found : int
required: int[]
conversion[j] = convert;
^
Lossy_Compression.java:85: incompatible types
found : int[]
required: int
jointPixel[destPosY][destPosX] = conversion[j];
^
4 errors

Brian