Symbian
Symbian OS Library

FAQ-0865 Why does my MIDlet fail when ported to the Nokia 3650 although it ran successfully on the Nokia 7650?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: General
Created: 04/09/2003 Modified: 04/11/2003
Number: FAQ-0865
Platform: Symbian OS v6.1

Question:
Why does my MIDlet fail when ported to the Nokia 3650 or Nokia 7650 v4.39 although it ran successfully on the Nokia 7650 v3.12? The error originates from a call to the Image.getGraphics() method.

Answer:
Nokia changed the implementation of the Image.getGraphics() method for software version 4.39. The implementation of Image.getGraphics() in version 3.12 returned a reference to the same Graphics object (instead of creating a new one every time), violating the MIDP 1.0 specification. Code similar to that shown below may fail on v4.39 based devices such as the Nokia 3650 due to memory full reasons if the draw() method is called multiple times.

    public class MyUI {
    Image buffer;
    ...

    public MyUI(){
    buffer = Image.createImage(canvasW, canvasH);
    }

    public void draw(){
    Graphics g = buffer.getGraphics();
    g.setColor(color);
    ....
    }
    ...
    }


    Instead make the Graphics context an instance variable as follows

    public class MyUI {
    Image buffer;
    Graphics g;
    ...

    public MyUI(){
    buffer = Image.createImage(canvasW, canvasH);
    g = buffer.getGraphics();
    }

    public void draw(){
    g.setColor(color);
    ....
    }
    ...
    }


    For more details refer to the Forum Nokia Technical Note "Known memory issues with the Nokia 7650"http://www.forum.nokia.com/main/1,,1_0_10,00.html