Search code examples
blackberrycheckbox

How to send a checkbox field that is checked as a parameter to pushScreen


I wrote a simple program that will push to another screen whenever a field in checkbox in checked. this is the code:

public MyScreen()
{        
    // Set the displayed title of the screen       
    setTitle("SFTS");

    LabelField dateLabel = new LabelField("Today's Route Paln",Field.FIELD_HCENTER);

    add(dateLabel);
    _dateField = new DateField("Date/time: ", System.currentTimeMillis(), DateField.DATE_TIME);
    add(_dateField);          

    add(new SeparatorField());

    for(i=0;i<name.length;i++)
    {
        s[i]=new CheckboxField(name[i]+","+addr[i]+","+time[i],false);
        add(s[i]);
        s[i].setChangeListener(f);
    }       
}    

FieldChangeListener f=new FieldChangeListener() {

    public void fieldChanged(Field field, int context) {
        UiApplication.getUiApplication().pushScreen(new secondscreen(field));
    }

};

There is no error while compiling but whenever i check the field in checkbox, i am getting a IllegalStateExcpetion in the emulator. Please help me out. Thank you


Solution

  • You need to declare the size of the Checkbox.

    s=new CheckboxField[name.length];

    try this, I think you got the solution.