LWUIT ArrayOutOfBoundException

196 views Asked by At

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

1

There are 1 answers

4
bharath On

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.