2011-11-10 29 views
-1

我是LWUIT的新手,尽管我发现使用它非常有趣,但我一直面临着预览我生成的任何MIDlet的挑战。每次我在模拟器中运行MIDlet时,都会在模拟器的屏幕上显示一个ArrayOutOfBOundException作为窗体,并且只有在窗体上按OK后才会退出。LWUIT 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... 
     } 
    } 

它的形式显示出来这个代码,但它并没有显示它的主题我created.The主题的名称是“working.res”和我把它在res文件夹中。谢谢

+4

向我们展示你的代码,我们也许能够帮助 –

回答

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. 
+0

我做了什么,你告诉我,我有mentioned.The问题是,实际上LABEL确实显示,但它没有出现在主题上。主题根本没有出现。我无法将标签贴在主题和其他gui组件上。感谢 – fyzil

+0

您在显示“Form”后调用了'Resource'。这是不对的。尝试调用Display.init(this);'下方的'Resource'。看看我的更新。 – bharath

+0

主题的路径也可能不正确。如果主题在jar的根目录下,它应该是/ not/res。 –