LWUIT 数组越界异常

发布于 2024-12-15 06:25:46 字数 1711 浏览 3 评论 0原文

我是 LWUIT 的新手,尽管我发现它使用起来非常有趣,但预览我生成的任何 MIDlet 一直面临着挑战。每次我在模拟器中运行 MIDlet 时,都会收到 ArrayOutOfBOoundException 在模拟器屏幕上显示为表单,并且只有在表单上按“确定”后才会离开。

这是我的代码

    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

I am new to LWUIT, and even though I am finding it very interesting to use, I have been having the challenge of previewing whatever MIDlet I generate. Each time i run the MIDlet in an emulator, I get an ArrayOutOfBOundException displaying as a form on the screen of the emulator and will only leave after pressing OK on the form.

This is my code

    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...
      }
    }

It displayed the form with this code but it didnt display it on the theme i created.The name of the theme is "working.res" and i included it in a res folder in the project folder.Thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情何以堪。 2024-12-22 06:25:46

当我运行您的代码时,我在这一行得到 illegalargumentExceptionbottomText.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.

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文