Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Turning TextField Uneditable on and off

This topic is 5422 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I’m just getting started with J2ME so I thought I would play around with some of the high level UI components. What I’m trying to do is have a ChoiceGroup control whether a TextField is editable or not. However for some reason a NullPointerException gets thrown and I don’t know why. This is the code I have:
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;

public class EditableTextFieldMIDlet extends MIDlet
	private boolean startup;
	Display display;

	EditableTextFieldForm editableTextFieldForm;

	public EditableTextFieldMIDlet()
		startup = true;

	public void startApp()
			display = Display.getDisplay(this);
			editableTextFieldForm = new EditableTextFieldForm(this);
			startup = false;


	public void pauseApp()

	public void destroyApp(boolean unconditional)

	public void exitRequested()

class EditableTextFieldForm extends Form implements CommandListener, ItemStateListener
	EditableTextFieldMIDlet midlet;

	ChoiceGroup allowEditingChoiceGroup;
	TextField textField;

	Command exitCommand;

	public EditableTextFieldForm(EditableTextFieldMIDlet main)
		super("Editable Text Field");

		midlet = main;

		allowEditingChoiceGroup = new ChoiceGroup("Allow Editing", Choice.EXCLUSIVE);
		allowEditingChoiceGroup.append("Off", null);
		allowEditingChoiceGroup.append("On", null);

		textField = new TextField("String:", null, 10, TextField.UNEDITABLE);


		exitCommand = new Command("Exit", Command.EXIT, 1);

	public void commandAction(Command c, Displayable d)
		if(c == exitCommand)

	public void itemStateChanged(Item item)
		if(item == allowEditingChoiceGroup)
			if(allowEditingChoiceGroup.getSelectedIndex() == 1)
				// On

You can select between the two choices without any problem but when you give focus to the TextField and then change the value in the ChoiceGroup the following stack trace for the exception comes up:
	at com.sun.midp.lcdui.DefaultInputMethodHandler.setConstraints(+63) 
	at javax.microedition.lcdui.TextField$InputMethodClientImpl.setConstraints(+20) 
	at javax.microedition.lcdui.TextField.setConstraints(+37) 
	at EditableTextFieldForm.itemStateChanged(+27) 
	at javax.microedition.lcdui.Form.callItemStateChanged(+27) 
	at javax.microedition.lcdui.Display.callItemStateChanged(+14) 
	at javax.microedition.lcdui.Display.access$900(+5) 
	at javax.microedition.lcdui.Display$DisplayAccessor.callItemStateChanged(+8) 
	at javax.microedition.lcdui.Display$DisplayManagerImpl.callItemStateChanged(+10) 
	at com.sun.midp.lcdui.DefaultEventHandler.itemStateChangedEvent(+17) 
	at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+835) 
Any insights would be greatly appreciated. Cheers.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!