-1

私は LWUIT を初めて使用します。使用するのは非常に興味深いと思いますが、MIDlet生成したものをプレビューするという課題に直面しています。MIDletエミュレーターで実行するたびに、エミュレーターArrayOutOfBOundExceptionの画面にフォームとして表示され、フォームで [OK] を押すと終了します。

これは私のコードです

    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

4

1 に答える 1

1

While im running your code im getting illegalargumentexception on this line, bottomText.setTextPosition(Component.CENTER);.

Because you can't set the label text position as Component.CENTER. You should use the label text position as LEFT/RIGHT/BOTTOM/TOP. If you change the label text position as I mentioned, it will work properly.

So If you getting ArrayOutOfBOundException, you did a mistake on some other place. Try to debug your application and find out where did you made a mistake.

Update:

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.
于 2011-11-14T14:26:44.440 に答える