-1

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

bharath
  • 14,283
  • 16
  • 57
  • 95
fyzil
  • 25
  • 1
  • 4

1 Answers1

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.
bharath
  • 14,283
  • 16
  • 57
  • 95
  • I did what you told me as mentioned.The problem i am having is that the LABEL actually did show but it didnt appear on theme.The theme didnt appear at all.I cant get to put the label on theme,and other gui components.thanx – fyzil Nov 14 '11 at 19:17
  • You called `Resource` after showing the `Form`. Its wrong. Try to call the `Resource` below of the `Display.init(this);`. Look on my update. – bharath Nov 15 '11 at 05:33
  • The path to the theme is probably incorrect as well. If the theme is in the root of the jar it should be / not /res. – Shai Almog Nov 17 '11 at 05:04
  • @ Shai, If we added the `res` folder in Libraries and properties, it should work. Right? – bharath Nov 17 '11 at 05:24