LWUIT ArrayOutOfBoundException

时间:2011-11-10 19:38:53

标签: java java-me lwuit lwuit-resource-editor

我是LWUIT的新手,虽然我觉得使用它很有趣,但我一直面临着预测我生成的任何MIDlet的挑战。每次我在模拟器中运行MIDlet时,我都会在模拟器的屏幕上显示ArrayOutOfBOundException作为表单,并且只有在表单上按“确定”后才会离开。

这是我的代码

    import javax.microedition.midlet.*;

    import com.sun.lwuit.*;
    import com.sun.lwuit.events.*;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.plaf.UIManager;
    import com.sun.lwuit.util.Resources;
    import java.io.IOException;

    public class Ruwwa extends MIDlet implements ActionListener {
      public void startApp() {
       Display.init(this);

    Form f = new Form("");

    f.setTitle("Mairuwa Portal");

    Label bottomText = new Label();
    bottomText.setText("Welcome to the Mairuwa Portal");
    bottomText.setTextPosition(Component.CENTER);
    f.addComponent(bottomText);

    Command exitCommand = new Command("Exit");
    f.addCommand(exitCommand);
    f.addCommandListener(this);

    f.show();

    try {
      Resources r = Resources.open("/res/working.res");
       UIManager.getInstance().setThemeProps(r.getTheme("Mairuwa Theme"));
         } catch (IOException ioe) {
             // Do something here.
         }

    }

    public void pauseApp() {}

    public void destroyApp(boolean unconditional) {}

    public void actionPerformed(ActionEvent ev) {
       Label label = new Label();
       label.setText("Initiating IO, please wait...");
       Display.getInstance().invokeAndBlock(new Runnable() {
    public void run() {
       // perform IO operation...
      }
    });
    label.setText("IO completed!");
     // update UI...
      }
    }

它显示了带有此代码的表单,但它没有在我创建的主题上显示它。主题的名称是“working.res”,我将它包含在项目文件夹的res文件夹中.Thanx

1 个答案:

答案 0 :(得分:1)

我在运行您的代码时,illegalargumentexception就行了bottomText.setTextPosition(Component.CENTER);Component.CENTER

因为您无法将标签文字位置设置为LEFT/RIGHT/BOTTOM/TOP。您应该将标签文本位置用作ArrayOutOfBOundException。如果您按照我的提法更改标签文字位置,它将正常工作。

所以如果你得到Display.init(this); try { Resources r = Resources.open("/res/working.res"); UIManager.getInstance().setThemeProps(r.getTheme("Mairuwa Theme")); } catch (IOException ioe) { // Do something here. } // your code. ,你在其他地方犯了一个错误。尝试调试您的应用程序,找出你犯了什么错误。

<强>更新

{{1}}
相关问题