我正在尝试创建一个简单的诺基亚s40应用程序来添加两个数字(仅用于练习),我在代码中找不到任何错误,所以请帮忙,
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.StringItem;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class main extends MIDlet {
Display disp;
Form start;
TextField a, b;
StringItem sum;
main(){
disp = Display.getDisplay(this);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-g enerated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
start = new Form("Start");
a = new TextField("A", "Enter A", 40, TextField.NUMERIC);
b = new TextField("B", "Enter B", 4, TextField.NUMERIC);
sum = new StringItem("Sum", "hello");
start.append(a);
start.append(b);
start.append(sum);
disp.setCurrent(start);
}
}
然而,当我注释掉这两行时,我的代码开始工作但没有显示,请帮助。
a = new TextField("A", "Enter A", 40, TextField.NUMERIC);
b = new TextField("B", "Enter B", 4, TextField.NUMERIC);
start.append(a);
start.append(b);
答案 0 :(得分:3)
您的代码抛出IllegalArgumentException,因为初始内容字符串(“Enter A”)不遵守约束(NUMERIC)。你应该使用:
a = new TextField("Enter A", "0", 40, TextField.NUMERIC);
b = new TextField("Enter B", "0", 4, TextField.NUMERIC);