Java me LWUIT 1.4:为什么这个文本区域有时会出现重复?

Java me LWUIT 1.4:为什么这个文本区域有时会出现重复?,java-me,lwuit,midp,Java Me,Lwuit,Midp,我从包含文本区域的对话框创建了一个类: public class Alert extends Dialog { private Container c = new Container(new BorderLayout()); private Label titre = new Label("Mobile Banking"); private TextArea chp; private Command[] comms; public Alert(String

我从包含文本区域的对话框创建了一个类:

public class Alert extends Dialog {
    private Container c = new Container(new BorderLayout());
    private Label titre = new Label("Mobile Banking");
    private TextArea chp;
    private Command[] comms;
    public Alert(String text, Command[] comms)
    {
        super();
        titre.setUIID("titre_alert");
        titre.setAlignment(Label.CENTER);
        this.comms = comms;
        setAutoDispose(true);
        for (int cmd=0; cmd<comms.length; cmd++)
            addCommand(comms[cmd]);
        chp = new TextArea();
        chp.setEditable(false);
        chp.setAlignment(Label.CENTER);
        chp.getSelectedStyle().setBorder(null);
        chp.getUnselectedStyle().setBorder(null);
        chp.getSelectedStyle().setBgColor(this.getStyle().getBgColor());
        chp.getUnselectedStyle().setBgColor(this.getStyle().getBgColor());
        if (text.length() % 2 != 0)
            text = " ".concat(text);
        while (text.substring(0, (text.length()/2)+1).length() < chp.getMaxSize()/2)
        {
            text = " ".concat(text);
        }
        chp.setText(text);
        c.addComponent(BorderLayout.NORTH, titre);
        c.addComponent(BorderLayout.CENTER, chp);
    }
    public Command affiche()
    {
        return show(null, c, comms);
    }
}
问题是,有时调用
affiche()
方法时显示的文本是重复的:它应该只显示
计费效果成功的文本但有时它会显示文本以及
计费效果


那么,如何使文本参数只显示而不重复?

您在单独的线程上调用LUIT,这是非法的。您需要连续使用Display.call以避免文本布局代码中出现竞争条件。大概是这样的:

Display.getInstance().callSerially(new Runnable() {
   public void run() {
       // your LWUIT code here, no need for repaints 
   }
});

更好的方法是将LWIT4IO用于您的网络,因为它可以无缝地为您实现这一点。

“但有时它会显示文本,并且”,在什么情况下会产生这个错误?情况是不可预测的:但是线程执行的任务是一个httpconnection,它将数据从PC下载到手机。非常感谢Shai Almog
Display.getInstance().callSerially(new Runnable() {
   public void run() {
       // your LWUIT code here, no need for repaints 
   }
});