I'm trying to read images from the phone's memory card and i get the out of memory error: java.lang.outofmemoryerror:nativeDecodeImage
this is my code:
Code:
readFile("file:///E:/Images/Photo0008.jpg")
and the method readFile:
Code:
private Image readFile(String path) {
Image image = null;
try {
FileConnection fc = (FileConnection)Connector.open(path, Connector.READ);
if(!fc.exists()) {
System.out.println("File doesn't exist!");
}
else {
int size = (int)fc.fileSize();
InputStream is = fc.openInputStream();
byte bytes[] = new byte[size];
int bytesRead = 0;
while (bytesRead < size) {
bytesRead += is.read(bytes, bytesRead, size - bytesRead);
}
image = Image.createImage(bytes, 0, size);
}
} catch (IOException ioe) {
System.out.println("IOException: "+ioe.getMessage());
} catch (IllegalArgumentException iae) {
System.out.println("IllegalArgumentException: "+iae.getMessage());
}
return image;
}
What can i do to solve this problem?