Invalid Attribute Error
I am using JavaMe.
Every time I attempt to initialize a List object I receive the following error:
The value for attribute null is not in the proper format
I am using Eclipse and JRE 6 on Mac OSX Lion.
Here is my simple code:
import javax.microedition.midlet.MIDlet;
import javax.microedition.lcdui.*;
public class ListTest extends MIDlet implements CommandListener {
private Display di开发者_如何学JAVAsplay;
private List optionsItem;
private Command exit;
public ListTest(){
optionsItem = new List("List types of Item", Choice.IMPLICIT);
}
protected void startApp() {
display = Display.getDisplay(this);
optionsItem.append("TextField",null);
optionsItem.addCommand(exit);
optionsItem.setCommandListener(this);
display.setCurrent(optionsItem);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
public void commandAction(Command c, Displayable d) {
}
}
Are you initializing your member variables correctly?
The Command object is never initialized, i.e. 'exit' is null
private Command exit;
The value for attribute... error seems to point to some problem in MIDlet JAD.
It looks like your MIDlet fails to install or launch even before the buggy code with uninitialized command pointed to in previous answer gets a chance to execute.
To debug issues like that I'd use the simplest code that could possibly work. Like say this:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class SmokeTest extends MIDlet {
protected void startApp() {
Display display = Display.getDisplay(this);
Form form = new Form("form");
form.addCommand(new Command("Exit", Command.EXIT, 1));
form.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
notifyDestroyed();
}
});
display.setCurrent(form);
}
protected void pauseApp() { }
protected void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}
If MIDlet installs and launches OK, above code will display a Form with title "form" and with command "Exit". If that doesn't happen, it's better to study Eclipse documentation to figure what's wrong with J2ME config settings.
精彩评论