If you call repeatedly the method Image.getGraphics() of a single image in the Series 60 MIDL implementation, the method throws an ArrayIndexOutOfBoundsException at some time.
Is this a standard conforming behavior?
Is it not allowed to call this method more than a few times?
Example:
In the following method, the call img.getGraphics() throws the exception when y=18. Is reproduceable with the Series 60 MIDL emulator and on the Nokia 3650 device. All other emulators I have tested do not throw an exception.
private void repaintImage() {
int sizey = getHeight();
int sizex = getWidth();
Image img = Image.createImage(sizex, sizey);
for(int y=0;y<sizey;y++) {
Graphics g = img.getGraphics();
g.setColor(208);
g.drawLine(57, y, 57, y);
}
}
Moving the line 'Graphics g = img.getGraphics();' out of the loop
removes the exception.
The API documentation just says that at each call a new object is created at each call of Image.getGraphics() and that the object has an indefinite lifetime. Though I would expect that unused objects are garbage collected...
Hans

Reply With Quote



