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
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810
Accepted Solution

manager.replace twice?

Hi all.

 

I am trying to replace a field of my screen and have done it already:

 

fOriginalField.getManager().replace(fOriginalField, fNewField);

 

But now I cannot do the opposite (I want to return it to its original state). I get a null pointer exception when I try that.

 

fOriginalField.getManager().replace(fNewField, fOriginalField); -> null pointer exception !

 

Should this work ? I know that the replacement field must not belong to any manager, and I believe that causes the mess. Am I right ?

Or some intermediate code messes up with this procedure ?



"Listen carefully, I shall say this only once"
Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: manager.replace twice?

that is a tricky one.

in the first call you delete fOriginalField from the manager. fOriginalField is now a homeless field without any manager to take care of it.

in the second call you ask fOriginalField for its manager. fOriginalField is very unhappy about having no manager and throws a NullPointerException at you.

getting the manager from fields you add and delete just cries for this error :smileyhappy:
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
myraddin
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: manager.replace twice?

[ Edited ]

Yes,

Silly I was just writing a reply to this thread explaining what a stupid thing I did, when I got an email with your reply.

 

Thanks for your interest :smileyhappy:  and kind explanation

Message Edited by myraddin on 02-05-2009 03:37 PM


"Listen carefully, I shall say this only once"
New Developer
rentepatrick
Posts: 16
Registered: ‎02-03-2010
My Device: Curve 5430

Re: manager.replace twice?

Hi to all!

 

I have the exact same problem.

But I am not so good in english!

Can you tell me how to solve it please?

 

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: manager.replace twice?

hello rentepatrick,

please create an own thread for your question as this topic is already solved. did you try the solution already?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
rentepatrick
Posts: 16
Registered: ‎02-03-2010
My Device: Curve 5430

Re: manager.replace twice?

hi,

the problem is that I don't understant de solution.

 

Best regards

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: manager.replace twice?

if you remove a field from a manager this field now is not added to a manager. because you removed it.

if you call getManager on the field you get null. because it is not added to a manager.

if you try to do some operation on this non-existing manager you get a nullpointerexception. you can avoid this if you check for getManager returning null or change the logic of the code.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
rentepatrick
Posts: 16
Registered: ‎02-03-2010
My Device: Curve 5430

Re: manager.replace twice?

Thank you for your reply!

I have this:

 

public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        if(field == lst_City.typeField){  
            String s_Type = (String)lst_City.typeField.getChoice(lst_City.typeField.getSelectedIndex());
            s_Type = s_Type.toLowerCase();
            lst_City.constructRestList(s_Type);
            if(lst_City.typeField.getSelectedIndex()==0){
                lst_City.filteredRestListField.getManager().replace(lst_City.filteredRestListField, lst_City.restListField);
        
              }
            UiApplication.getUiApplication().invokeLater (new Runnable() {
                public void run()
                {
                   //Perform screen changes here.
               // replace(lst_City.restListField, lst_City.filteredRestListField);
                lst_City.restListField.getManager().replace(lst_City.restListField, lst_City.filteredRestListField);
                   lst_City.restListField = lst_City.filteredRestListField;

 

 

New Developer
rentepatrick
Posts: 16
Registered: ‎02-03-2010
My Device: Curve 5430

Re: manager.replace twice?

i also try this, I changed my code as you sugested and didn't work.

 

public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        if(field == lst_City.typeField){  
            String s_Type = (String)lst_City.typeField.getChoice(lst_City.typeField.getSelectedIndex());
            s_Type = s_Type.toLowerCase();
            lst_City.constructRestList(s_Type);
            if(lst_City.typeField.getSelectedIndex()==0){
                l  st_City.filteredRestListField =  lst_City.restListField;
              }
            UiApplication.getUiApplication().invokeLater (new Runnable() {
                public void run()
                {
                   //Perform screen changes here.
                lst_City.restListField.getManager().replace(lst_City.restListField, lst_City.filteredRestListField);
                   lst_City.restListField = lst_City.filteredRestListField;
                //Calling invalidate() on your screen forces the paint
                //method to be called.
                //invalidate();
                }

 

Please help me.