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
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Field added to manager while it is already parented.

I'm getting the subject error and can't find it on a quick search for related terms,

 

http://www.google.com/search?hl=en&q=site%3Ablackberry.com+field+added+manager+parented

 

It seems to occur on second attempt to invokeAndWait this run method,  

 

public void run()
  {
    MainScreen xx= new MainScreen();
    xx.add(new RichTextField(ms));
    xx.add(m_oops);
    pushScreen(xx);
    Dialog.alert(ms);
  popScreen(xx);   
   
   }

 

fwiw, m_opps is a bitmapfield.

 

I guess the larger question is how to backout all the "stuff" that happens when the above executes.

 

Thanks.

 

 

Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Field added to manager while it is already parented.

Calling deleteAll on the screen seems to fix the problem but I wasn't aware this needed to be done explicitly

as I assumed when it went out of scope ( ref count went to zero) everything would get cleaned up,

 

MainScreen xx= new MainScreen();
    xx.add(new RichTextField(ms));
    xx.add(m_oops);
    pushScreen(xx);
    Dialog.alert(ms);
    xx.deleteAll();
   // m_app._mainScreen.deleteAll();
  popScreen(xx);   

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Field added to manager while it is already parented.

As you have spotted, your problem is caused by the m_oops field being added to the Screen.  In addition to the Manager keeping a list of the Fields added, each Field keeps a reference to its owning manager (you can find a Field's manager by calling its getManager() method).  So even though your new Mainscreen was never explicitly referenced in your code, it was referenced by your field m_oops.  To tidy this up, you didn't need a deleteAll, just a delete for m_oops from your new MainScreen. 
Contributor
Posts: 35
Registered: ‎12-01-2011
My Device: BlackBerry 8520
My Carrier: Generic

Re: Field added to manager while it is already parented.

[ Edited ]

I have a bitmap that is a banner. I created as a singleton. Now im getting same error when i try to insert this bitmap in others screen.

So, i need to create this bitmap every time i want to put in on a screen?

 

edit: if u delete all from a screen before pushing a new one, when the user go back the constructor of the screen es not called so the fields are not added.

 

what should i do with the back button?

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Field added to manager while it is already parented.

" i need to create this bitmap every time i want to put in on a screen?"

 

The bitmap - no.  But the BitmapField must only be on one screen.

 

"when the user go back the constructor of the screen es not called so the fields are not added"

 

Correc

 

"what should i do with the back button?"

 

Don't delete the Fields. 

 

Why do you need a SIngleton BitmapField?