I'm trying to create a simple Nokia s40 app to add two numbers (just for practice), I could not find any error in my code, so please help,
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);
}
}
however when I comment out these two lines, my code start working but nothing to display then, please help.
a = new TextField("A", "Enter A", 40, TextField.NUMERIC);
b = new TextField("B", "Enter B", 4, TextField.NUMERIC);
start.append(a);
start.append(b);
Your code throws an IllegalArgumentException because the initial content string ("Enter A") does not respect the constraint (NUMERIC). You should use:
a = new TextField("Enter A", "0", 40, TextField.NUMERIC);
b = new TextField("Enter B", "0", 4, TextField.NUMERIC);