Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
soportev2p0
Posts: 9
Registered: ‎06-28-2010
My Device: N/A
Accepted Solution

Unpaired Graphics.pop(paint)

Hi

 

I just develop an app and I already tested on a BB 8120 simulator, but when I try to run it on a real BB 8120 I get this error

 

Uncaught exception: Unpaired Graphics.pop(paint) in class
com.v2p0.myapp.myappMainScreen $1 actual 5!=expected
6 clip (0,23)+(240,260)@(0,-23

 

My app was correctly installed and this error shows up when I tried to open my app from its icon.

 

How can I solve it? And, Why is it happening?

 

I am using JDE 4.3

Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520

Re: Unpaired Graphics.pop(paint)

I think the problem is related to with your ways to work with Graphics object. Could you provide us with some code snippet?

Got resolved! Press kudo icon!
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Unpaired Graphics.pop(paint)

Check that your development environment matches the device in terms of OS level, remember that you must develop using an OS that is less than or the same as the OS on the target device.

 

In this case, are you using the Graphics push and pop Context?

 

I agree with sonicboomboy that seeing some code might help.  In this case can we see the code around the error?

Please use plain text.
New Contributor
soportev2p0
Posts: 9
Registered: ‎06-28-2010
My Device: N/A

Re: Unpaired Graphics.pop(paint)

Hi

 

Here is a  fragment from my code

 

    LabelField head = new LabelField("Hello");
    Bitmap logoBitmap =  Bitmap.getBitmapResource("header.png");
    headField = new BitmapField(logoBitmap);
    add(headField);
    HorizontalFieldManager labelManager = new HorizontalFieldManager(Field.FIELD_HCENTER){               
           
        protected void paint(Graphics graphics) {
            
            try {
                  FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");
                  Font appFont = alphaSansFamily.getFont(Font.PLAIN, 8, Ui.UNITS_pt);
                  setFont(appFont);
              } catch (ClassNotFoundException e) {
           }
           
            graphics.setColor(0x00345a);
            graphics.clear();
            super.paint(graphics);
            } 
     };

    labelManager.add(head);
    add(labelManager);

 

 

This is part of my MainScreen and is the first thing I send to the screen. I think here could be my problem.

Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Unpaired Graphics.pop(paint)

I suspect your problem is that you are doing a setFont  in your paint method.  This gets recursive, because to process the setFont, the Field knows it has to repaint itself, which of course causes another setFont....


Is there anything wrong with this code?

 

    HorizontalFieldManager labelManager = new HorizontalFieldManager(Field.FIELD_HCENTER){               
           
        protected void paint(Graphics graphics) {
            graphics.setColor(0x00345a);
            graphics.clear();
            super.paint(graphics);
            } 
     };

     try {
         FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif");
         Font appFont = alphaSansFamily.getFont(Font.PLAIN, 8, Ui.UNITS_pt);
         labelManager.setFont(appFont);
     } catch (ClassNotFoundException e) {
     }

    labelManager.add(head);
    add(labelManager);

 

Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520

Re: Unpaired Graphics.pop(paint)

peter_strange, not sure exactly that method caused the problem. I testet (though already on 8120 simulator) the original code snippet and it seems to work. No exception has been thrown.

I think the author uses somewhere Graphics.pushContext(...) and related methods which can lead to exceptions.

Nevertheless let's wait for author's response.

Got resolved! Press kudo icon!
Please use plain text.
Developer
peter_strange
Posts: 19,609
Registered: ‎07-14-2008
My Device: Not Specified

Re: Unpaired Graphics.pop(paint)

sonicboomboy. - appreciate your input and I understand that the code might not throw an exception.  Just one question - do you think the OP should set the font as I suggest or as is done in the code snippet?

Please use plain text.
Developer
sonicboomboy
Posts: 466
Registered: ‎03-04-2009
My Device: 8520

Re: Unpaired Graphics.pop(paint)

peter_strange, 

you're right. The code to set a font has nothing to deal with paint(..) method (as in original) and should be a separate action.

Got resolved! Press kudo icon!
Please use plain text.