LWUIT 数组越界异常
我是 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当我运行您的代码时,我在这一行得到
illegalargumentException
,bottomText.setTextPosition(Component.CENTER);
。因为你不能将标签文本位置设置为
Component.CENTER
。您应该将标签文本位置用作LEFT/RIGHT/BOTTOM/TOP
。如果您按照我提到的方式更改标签文本位置,它将正常工作。因此,如果您收到
ArrayOutOfBoundException
,则说明您在其他地方犯了错误。尝试调试您的应用程序并找出哪里出错了。更新:
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 asLEFT/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: