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
Contributor
tusharpandey
Posts: 10
Registered: ‎01-19-2013
My Device: 9900
Accepted Solution

after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

i have two screens , first_one contains 17 fields & by a button_presnt in first screen i am reaching at second screen , at second screen after pop_screen(first) & push_screen(first) i am getting my first screen , now i want to delete 15 fields from this , but i am facing the error , that illegal arguement exception or "Attempt to delete a field that does not belong to the manager" ..... & Note this point , i have got the get_field_count from first screen .
try

{

UiApplication.getUiApplication().popScreen(object_to_supprot);
UiApplication.getUiApplication().pushScreen(object_to_supprot);
}
catch ( Exception err )
{
Dialog.inform("Error in loading page : "+err);
}

try
{
Dialog.inform("field count in home page : "+object_to_supprot.getFieldCount() );

int k = object_to_supprot.getFieldCount() - 1 ;

while ( k > 1 )
{
delete( object_to_supprot.getField(k) );
k-- ;
}
}
catch ( Exception err )

{

Dialog.inform("Error in work setting button pressed : "+err );

}

 

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

Re: after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

Like you I guess, I really can't see how this code is causing the problem that you see.

 

Can you tell us what index (k value) you are at when you see this exception?

 

Note that I'm not sure about your pop and then push.  I take it when you go to screen 2, you just push screen 1.  Then when you go back to screen 1, you leave screen two there, and pop screen 1 (which takes it off the display stack,) and then push it again.  This means you have screen 2 still on the display stack, but hidden by screen 1.  Is this what you wanted?

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

Re: after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

usually you don't delete fields.
java has garbage collection, you can just pop a screen and if it is no longer referenced it gets cleaned up.

to make transitions smoother it is also better to push the new screen before popping the old one.
many applications provide a screen stack where the old screen is not popped so you can go back to it, but that depends on your usecase of course.
----------------------------------------------------------
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
Contributor
tusharpandey
Posts: 10
Registered: ‎01-19-2013
My Device: 9900

Re: after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

actually , i can not delete anything  { k = 0 ...... end }  

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

Re: after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

you should ask yourself first why you want to delete anything in the first place.
----------------------------------------------------------
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
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

[ Edited ]

I'm going to disagree with Simon here.  I think deleting Fields from a Screen is a valid thing to do.  I can see cases for doing it when you use the same screen, but have two different sets of data which require slightly different Fields on display.  This is what seems to be happening here.

 

I have just realized what the problem is.

 

your code:

 

delete( object_to_supprot.getField(k) );

 

should be:

 

object_to_supprot.delete( object_to_supprot.getField(k) );

 

 

Your current code is effectively:

 

this.delete( object_to_supprot.getField(k) );

 

and 'this' is presumably your second screen.  You want to delete Fields from your first screen.

 

Can I ask you to review my first post and Simon's post again.  Please investigate how you use the display stack and make sure you are using it correctly. 

Contributor
tusharpandey
Posts: 10
Registered: ‎01-19-2013
My Device: 9900

Re: after using popScreen() than pushScreen() , how to delete the fields present in that first Screen .

thanks .