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: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel
Accepted Solution

Create checkboxes (Radio Button group like behaviour) gives StackOverflowError

Hi All,

 

  I am trying to create 3 checkboxes field on my screen and my intention is that if i select on checkbox then another selected checkbox should get unchecked. I have written some code but it is giving StackOverflowError.

 

final CheckboxField[] checkBoxField = new CheckboxField[3];
		checkBoxField[0] = cashCardCheckboxField;
		checkBoxField[1] = creditDebitCardCheckboxField;
		checkBoxField[2] = internetBankingCheckboxField;

		checkBoxField[0].setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				if(checkBoxField[0].getChecked()){
					checkBoxField[0].setChecked(false);
				}else{
					checkBoxField[0].setChecked(true);
				}
				if(context != FieldChangeListener.PROGRAMMATIC) {
					checkBoxField[1].setChecked(false); 
					checkBoxField[2].setChecked(false); 
				}
				if(checkBoxField[0].getChecked()){
					
					//Please wait Screen starts
					
					// call here a user defined function to populate the drop down list
					
					//Please wait Screen ends
				}
				
			}
		});
		
		checkBoxField[1].setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				if(checkBoxField[1].getChecked()){
					checkBoxField[1].setChecked(false);
				}else{
					checkBoxField[1].setChecked(true);
				}
				if(context != FieldChangeListener.PROGRAMMATIC) {
					checkBoxField[0].setChecked(false); 
					checkBoxField[2].setChecked(false); 
				}
				if(checkBoxField[1].getChecked()){
					
					//Please wait Screen starts
					
					// call here a user defined function to populate the drop down list
					
					//Please wait Screen ends
				}
				
			}
		});
		
		checkBoxField[2].setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				if(checkBoxField[2].getChecked()){
					checkBoxField[2].setChecked(false);
				}else{
					checkBoxField[2].setChecked(true);
				}
				if(context != FieldChangeListener.PROGRAMMATIC) {
					checkBoxField[0].setChecked(false); 
					checkBoxField[1].setChecked(false); 
				}
				if(checkBoxField[2].getChecked()){

					//Please wait Screen starts
					
					// call here a user defined function to populate the drop down list
					
					//Please wait Screen ends
				}
				
			}
		});

 

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

Re: Create checkboxes (Radio Button group like behaviour) gives StackOverflowError

The stack trace that you get with this error, will help you determine the recursive processing that is causing the problem.  Review that.

 

Guessing on the basis of what I see here, I would suspect that you change the check box values in the FieldChangeListener, which drives another invocation of your FieldChangeListener recursively.  I suggest you review the processing that you have, especially when context == FieldChangeListener.PROGRAMMATIC.

Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Create checkboxes (Radio Button group like behaviour) gives StackOverflowError

Hi Peter, Thanks for the reply.

 Meanwhile i have gone through various posts on the internet and i found two terms there.  Programmatic and Non-Programmatic change in context of CheckBoxField.  Could you please brief about these two terms?

 

Thanks

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

Re: Create checkboxes (Radio Button group like behaviour) gives StackOverflowError

Programmatic means you changed it in your program.  Otherwise it was changed by the user. 

Developer
Posts: 95
Registered: ‎07-24-2013
My Device: 9380
My Carrier: Airtel

Re: Create checkboxes (Radio Button group like behaviour) gives StackOverflowError

I am posting the code here.. Please help me out..It still gives StackOverflow error..

 

final CheckboxField[] checkBoxField = new CheckboxField[2];
		checkBoxField[0] = cashCardCheckboxField;
		checkBoxField[1] = creditDebitCardCheckboxField;
		
		checkBoxField[0].setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				
				if(context != FieldChangeListener.PROGRAMMATIC){  //It means manually clicked by User
					if(checkBoxField[0].getChecked()){
						checkBoxField[0].setChecked(false);
					}else{
						checkBoxField[0].setChecked(true);
						//Please wait Screen starts
						// call here a user defined function to populate the drop down list
						//Please wait Screen ends
					}
				}else{
					checkBoxField[0].setChecked(false);
				}
			}
		});

		checkBoxField[1].setChangeListener(new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				
				if(context != FieldChangeListener.PROGRAMMATIC){  //It means manually clicked by User
					
					if(checkBoxField[1].getChecked()){
						checkBoxField[1].setChecked(false);
					}else{
						checkBoxField[1].setChecked(true);
						//Please wait Screen starts
						// call here a user defined function to populate the drop down list
						//Please wait Screen ends
					}
					
				}else{
					checkBoxField[1].setChecked(false);
				}
			
			}
		});

 

 

 

Warm Regards.

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

Re: Create checkboxes (Radio Button group like behavior) gives StackOverflowError

Rather than asking us to look at your code and guessing where your problem is, the best option is for you to look at the stack trace you will get when debugging this code.  Look at the methods called, look for a recursive call, and you can figure out where the problem originates.

 

If you can't figure it out from that, then please let us know which method calls are involved in the recursive chain. 

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

Re: Create checkboxes (Radio Button group like behavior) gives StackOverflowError