我向水平管理器添加了两个按钮字段,当我尝试从另一个线程中删除管理器中的相同字段时,我得到一个 - 索引越界异常。
以下是我所做的一个例子 -
hfm.add(button1);
hfm.add(button2);
layout.add(hfm);
// on clicking button it starts a different thread which
// tries to delete the two buttonFields from the manager.
fieldChanged(Field field1,int arg1) {
if(field1==button1) {
populateUI();//This function starts a new Thread
}
}
populateUI() {
//...............//
run() {
//...............//
hfm.deleteAll();//this line gives an exception whereas
//on applying debug it shows field count as 2
}
}
那么为什么即使它有字段也显示错误?其余的一切都很好。
我甚至试图单独删除它......
hfm.delete(0);
hfm.delete(1);
但仍然是相同的错误 - 索引越界异常
答案 0 :(得分:1)
您可以使用:
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
HorizontalFieldManager newHfm = new HorizontalFieldManager();
replace ( hfm , newHfm );
}
});
瞧,瞧!你的hfm好像新..