开发者

Not able to delete a field from a Manager

开发者 https://www.devze.com 2023-03-14 03:54 出处:网络
i added two button fields to a Horizontal Manager and when i try to delete the same from the manager from a different thread i get an - index out of bounds exception.

i added two button fields to a Horizontal Manager and when i try to delete the same from the manager from a different thread i get an - index out of bounds exception.

Here is an example of what i did--

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 debu开发者_StackOverflow中文版g it shows field count as 2 
    }
}

So why is it showing error even when it has fields in it??? The rest everything are working fine.

i even tried deleting it individually...

hfm.delete(0);
hfm.delete(1);

but still the same error -- index out of bounds exception


You can use :

UiApplication.getUiApplication().invokeLater(new Runnable() {
  public void run() {   
  HorizontalFieldManager newHfm = new HorizontalFieldManager();
  replace ( hfm , newHfm );
  }
});

and voila! your hfm is good as new..

0

精彩评论

暂无评论...
验证码 换一张
取 消