TextField is an Item
object, and to use commands with it you need ItemCommandListener:
A listener type for receiving notification of commands that have been invoked on Item objects. An Item can have
Commands
associated with it. When such a command is invoked, the application is notified by having the commandAction() method called on theItemCommandListener
that had been set on the Item with a call to setItemCommandListener()...
Most likely reason for NullPointerException
you mentioned is that you did not set appropriate item command listener (it's null by default, thus when MIDP attempts to invoke command action, there is NPE).
To get what you want, besides creating and adding commands, you need to create item command listener, implement code to handle commands in it, then associate your text field with this listener:
myTextField.setItemCommandListener(myItemCommandListener);