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
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Exception: tried to remove FieldWithFocus

I am getting an exception : tried to remove FieldWithFocus when using the API function:

 

Manager.replace(oldField,newField);

 

I do understand why the exception is happening, but according to the documentation, it should not happen.

The doc says the following:

 

" Removes a field from this Manager and replaces it with another field. The specified oldField must be a direct child of this manager and the specified newField must not be being managed by any Manager, including this one.

If oldField had the focus and newField is focusable, then Field.setFocus() will be invoked on newField after it is added to this manager. "

 

So, is this a bug? or am i missing something?

 

Thanks

BlackBerry Development Advisor
Posts: 15,809
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Exception: tried to remove FieldWithFocus

It sounds like you are making the call from outside of the main event thread.  Please see the link below for more information.

 

How to - Update a screen on the Main Event Thread
Article Number: DB-00136

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800256/...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Exception: tried to remove FieldWithFocus

The call is made from the main event thread.

I have also noticed in other places that if a button has the focus and I try to remove it from its manager, it gives the same exception.

My work around this exception is to make sure  to first remove the focus from a field/button that is going to be removed from its manager. And that is what the replace function is supposed to do according to its documentation.

 

Thanks

BlackBerry Development Advisor
Posts: 15,809
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Exception: tried to remove FieldWithFocus

What BlackBerry model and handheld software version are you seeing this on?  You can find this under Options, About on the BlackBerry.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Developer
Developer
Posts: 283
Registered: ‎07-22-2008
My Device: Not Specified

Re: Exception: tried to remove FieldWithFocus

This is happening on both the simulator and the BB device.

I am using JDE 4.2.1

and the device is BB 8300, v4.2.2.89 (platform 2.4.0.39)

 

thanks

BlackBerry Development Advisor
Posts: 15,809
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Exception: tried to remove FieldWithFocus

I haven't been able to reproduce this one.  From where are you calling the replace method from?  Can you post a code snippet that triggers the exception? Are you seeing this behaviour in the version 4.5.0 BlackBerry JDE (and included simulators)?
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.