When I try to load images from phone memmory I get Out Of Memory errorjava/lang/OutOfMemoryError or nativedecodeImage . Some images in phone memory are of 12kd and while some others are around 589kb or 600kb. The small sized images are fetched to a list but when it comes to larger sized images it thrown the OOM error..??
This is my code
FileConnection finalConnection;
try
{
fc.close();
finalConnection = (FileConnection) Connector.open(path, Connector.READ_WRITE);
if(finalConnection.exists())
{
InputStream fis = finalConnection.openInputStream();
long overallSize = finalConnection.fileSize();
int length = 0;
byte[] imageData = new byte[0];
while (length < overallSize)
{
byte[] data = new byte[CHUNK_SIZE];
int readAmount = fis.read(data, 0, CHUNK_SIZE);
byte[] newImageData = new byte[imageData.length + CHUNK_SIZE];
System.arraycopy(imageData, 0, newImageData, 0, length);
System.arraycopy(data, 0, newImageData, length, readAmount);
imageData = newImageData;
length += readAmount;
}
fis.close();
finalConnection.close();
System.out.println("LENGTH IS " + length);
if (length > 0)
{
image = Image.createImage(imageData, 0, length);
}
}
else
{
System.out.println("NO PATH FOR IMAGE");
}
}
catch (Exception e)
{
System.out.println("Image.createImage(imageData, 0, length) " +e.toString());
}
catch(Error e)
{
System.out.println("Image.createImage " + e);
}
The point where I get error is at
image = Image.createImage(imageData, 0, length);
Does anyone have any idea about this. Am stuck with this thing for few days. Am working on S40 devices Nokia 311. Netbeans MIDP 2.0