J2ME诺基亚s40应用程序初学者在使用表单时找不到错误



我正在尝试创建一个简单的诺基亚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);

您的代码抛出一个IllegalArgumentException,因为初始内容字符串("Enter A")不遵守约束(NUMERIC)。您应该使用:

a = new TextField("Enter A", "0", 40, TextField.NUMERIC);
b = new TextField("Enter B", "0", 4, TextField.NUMERIC);

相关内容

  • 没有找到相关文章

最新更新