我写了一个简单的程序,只要选中复选框中的字段,它就会推送到另一个屏幕。这是代码:
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));
}
};
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));
}
};
编译时没有错误,但每当我选中复选框中的字段时,我在模拟器中得到一个IllegalStateExcpetion。请帮帮我。谢谢
答案 0 :(得分:0)
您需要声明复选框的大小。
s = new CheckboxField [name.length];
试试这个, 我想你得到了解决方案。