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
patilajayr
Posts: 404
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi

Illegal state exception :Field added to a manager while it is already parented.

Hello friends,

                    I face the exception illegal state exception :Field added to a manager while it is already parented. When i call below function second time,  means when I login and create the object of profile page. And add element to vertical field manager  vfm object. The second time when i come to that page i get the Exception.

 

 

Public class Profile extends MainScreen implements FieldChangeListener, 
{
IOThread t1;
LabelField lbl=new LabelField();
BitmapField b1,b2,b3,b4,b5;
public static VerticalFieldManager vfm=new VerticalFieldManager()
{ // If all component not arrange in single screen than we give color to VerticalFieldManager
protected void paint(Graphics g)
{
g.setBackgroundColor(13559791);
g.clear();
g.setColor(Color.BLACK);
subpaint(g);
}
};
public Profile()
{
try
{


String Img_url= Login_Screen.strg[18];
String img_u= replaceStr(Img_url);
getimage(img_u);
Bfimage.setSpace(15, 0);
lbl.setMargin(0, 0, 0,30);
setTitle(lblHeader);
hfm_P_Image.add(Bfimage);
hfm_P_Image.add(lbl);
lblbasic= new CustomLabel("Basic profile::",LabelField.NON_FOCUSABLE|DrawStyle.HCENTER | DrawStyle.VCENTER,Display.getWidth(),Display.getHeight()/10,Color.RED,13559791,Color.GREEN);
lblsocial= new CustomLabel("Social Profile::",LabelField.NON_FOCUSABLE|DrawStyle.HCENTER | DrawStyle.VCENTER,Display.getWidth(),Display.getHeight()/10,Color.RED,13559791,Color.GREEN);
logout= new CustomLabel("Logout", Field.FOCUSABLE
| FIELD_LEFT |DrawStyle.RIGHT|LabelField.RIGHT| Font.UNDERLINED, (Display.getWidth()/7),
Display.getHeight() / 15, 12441443, 13559791, Color.RED);
lblsearch= new CustomLabel("Search:", Field.FOCUSABLE
| FIELD_LEFT |DrawStyle.RIGHT|LabelField.RIGHT| Font.UNDERLINED, (Display.getWidth()/7),
Display.getHeight() / 15, 12441443, 13559791, Color.RED);
for(int i=0;i<15;i++)
{
edf[i]=new EditField(EditField.NO_NEWLINE);
edf[i].setEditable(false);
}
for(int j=0;j<str.length;j++)
{
cma[j] =new CustomLabel(""+str[j],LabelField.NON_FOCUSABLE| DrawStyle.VCENTER,Display.getWidth()/2,Display.getHeight()/10,Color.RED,13559791,Color.BLACK);
cma[j].setMargin(0, 0, 0, 15);
}
HorizontalFieldManager hfm_Header= new HorizontalFieldManager();
HorizontalFieldManager hfm[]=new HorizontalFieldManager[15];
for(int i=0;i<15;i++)
hfm[i]=new HorizontalFieldManager(HorizontalFieldManager.NO_HORIZONTAL_SCROLL
| HorizontalFieldManager.NO_VERTICAL_SCROLL | HorizontalFieldManager.USE_ALL_WIDTH);
setTitle(lblHeader);
hfm_Header.add(logout);
hfm_Header.add(lblsearch);
hfm_Header.add(lbledit);
vfm.add(hfm_Header);
vfm.add(hfm_smallImage);
vfm.add(new SeparatorField());
logout.setMargin(0,10,0,15);
lblsearch.setMargin(0,0,10,0);
lbledit.setMargin(0,0,0,15);
vfm.add(hfm_P_Image);
vfm.add(lblbasic);
for(int m=0;m<hfm.length;m++)
{
hfm[m].add(cma[m]);
hfm[m].add(edf[m]);
}
for(int i=0;i<9;i++)
vfm.add(hfm[i]);
vfm.add(new SeparatorField());
lblsocial.setMargin(10,0,0,0);
vfm.add(lblsocial);
for(int i=9;i<15;i++)
vfm.add(hfm[i]);
logout.setChangeListener(this);
lblsearch.setChangeListener(this);
lbledit.setChangeListener(this);

setdata();
add(vfm); // here i get that excetion when i come second time on that line.

}
catch(Exception ex)
{
Dialog.alert("Exception_p"+ex);
}
}

 any one tell me what shuld i do to fix the problem. becase when i execute all page fisrt time i work properly but when i come again last page i get that execption.

help me friends,

 thanks

ajay

 

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Illegal state exception :Field added to a manager while it is already parented.

you can add every field only once to a manager. this means you have to either update the existing fields or create new ones to add. as you create vfm only in the beginning your code tries to add it a second time which is not possible.
----------------------------------------------------------
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
Please use plain text.
New Developer
pasha701
Posts: 45
Registered: ‎05-25-2010
My Device: 8300
My Carrier: developer

Re: Illegal state exception :Field added to a manager while it is already parented.

[ Edited ]

Field "vfm" is static.

When you first time come to this page, "vfm" added to first instance.
When you second time come to this page, "vfm" is added to second instance. Exception here becuase "vfm" already assigned to first instance.

Make "vfm" non-static or remove from current parent when assign to next.

Please use plain text.
Developer
patilajayr
Posts: 404
Registered: ‎07-28-2010
My Device: 8000
My Carrier: hi

Re: Illegal state exception :Field added to a manager while it is already parented.

Hello,

         i Solve my problem. but one query is that. i am creating a application like face book. if the user is doing some changes in his profile and he want to come again his profile than he want to se updated profile. so what shuold i do to show upadate profile ??

        one issues is that suppos i want to access the one valuse of another class than i want to mantion that class public static and i face that exception when i declare that static than what shuold i get the data form another class with out the use of static variable??

        help me friends,

 thanks

   ajay

Please use plain text.
Developer
simon_hain
Posts: 16,010
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Illegal state exception :Field added to a manager while it is already parented.

declare the fields you use in the screen. you can use setText, setBitmap etc to update the values of the fields. you can define a public method in the screen to update them from outside, for example using an interface.
----------------------------------------------------------
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
Please use plain text.
New Member
coder23
Posts: 2
Registered: ‎04-19-2013
My Device: blackberry bold
My Carrier: GSM

Re: Illegal state exception :Field added to a manager while it is already parented.

Ajay can u post Your code , how u solved the problem . i M also facing same issue while updating lists in richlist, with spinner . for first time it works fine , but second time it gives illegal exception : field already parented .here m posting my code :

 

void showSpinnerDialog(int type) {
		if (_customSpinnerPopup == null) {

			_customSpinnerPopup = new CustomSpinnerPopup();
		}
		UiApplication.getUiApplication().pushModalScreen(_customSpinnerPopup);

		if (_customSpinnerPopup.isSet()) {

			String choice = _customSpinnerPopup.getChoice();
			
			_editFieldSpinbox.setText(choice);

			getAlbumsForLanguage(choice);
			
		}

	}

	private void getAlbumsForLanguage(String choice) {

		language = choice;
	
	    fieldManager.deleteAll();

		final RichList list = new RichList(fieldManager, true, 2, 1);

		songItemsList = new Vector();
		songItemsList = ServerAPI.getNewSongsForLanguage(language, null);

		for (int i = 0; i < songItemsList.size(); i++) {

			SongItem songItem = (SongItem) songItemsList.elementAt(i);
			list.add(new Object[] { bitmap1, songItem.getName(),
					"Artist:" + songItem.getArtist(),
					"Movie: " + songItem.getMovie() });
			
		}
        add(fieldManager);
	
		
		list.setFocusPolicy(TableController.ROW_FOCUS);
		list.setCommand(new Command(new CommandHandler() {

			/**
			 * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata,
			 *      Object)
			 */
			public void execute(ReadOnlyCommandMetadata metadata, Object object) {
			
				
				SongItem song = (SongItem) songItemsList.elementAt(list.getFocusRow());

				Dialog.alert("exe !" + song.getName());

 Please help me . 

 

Please use plain text.
New Member
coder23
Posts: 2
Registered: ‎04-19-2013
My Device: blackberry bold
My Carrier: GSM

Re: Illegal state exception :Field added to a manager while it is already parented.

can u please specify , how u solved the above issue ?I am new to blackberry please help me
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Illegal state exception :Field added to a manager while it is already parented.

Which statement is giving you this error.

Please use plain text.