Hello,
I'm starting in Java ME development, but when i finished the code, that i'm developing using Eclipse, it shows that my code have an error, with that red x in the left of the code line, here is the code:

package comm;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Form;

public class comm extends MIDlet implements CommandListener {
    private Display display;
    private Form inicio;
    private Form logado;
    private Form recusado;
    private Command cancelar;
    private Command login;
    private Command info;
    private Command help;
    private Command naousuario;
    private Command voltar;
	
	public comm() {
		inicio = new Form("Entrar");
		cancelar = new Command("Cancelar", Command.CANCEL, 0);
		login = new Command("Login", Command.OK, 1);
		info = new Command("Info", Command.OK, 1);
		help = new Command("Help", Command.OK, 1);
		inicio = new Form("Logado");
		recusado = new Form("Não Usuário");
		logado = new Form("Logado");
		naousuario = new Command("Não Usuário", Command.OK, 1);
		voltar = new Command("Voltar", Command.BACK, 0);
	}

	protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
		notifyDestroyed();
	}

	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	protected void startApp() throws MIDletStateChangeException {
		// Form Inicial
		display = Display.getDisplay(this);
		inicio.addCommand(cancelar);
		inicio.addCommand(login);
		inicio.addCommand(info);
		inicio.addCommand(help);
		inicio.addCommand(naousuario);
		inicio.setCommandListener(this);
		
		// Form Usuário Logado
		logado.addCommand(info);
		logado.addCommand(voltar);
		logado.setCommandListener(this);
		
		// Form Não Usuário
		recusado.addCommand(voltar);
		recusado.setCommandListener(this);
		display.setCurrent(inicio);
	}

	public void commandAction(Command c, Displayable d) {
		if (c == cancelar) {
			destroyApp(true);
		} else if (c == login) {
			display.setCurrent(logado);
		} else if (c == naousuario) {
			display.setCurrent(recusado);
		} else if (c == voltar) {
			display.setCurrent(inicio);
		}
	}
}

The error is in the line 67, and the error detail that is in the Problems tab is here:

Unhandled exception type MIDletStateChangeException

What is wrong?

Thanks,
Nathan Paulino Campos

Member Avatar for harsh2327

It is silly mistake.
Change your line no. 35 from

protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {

to

protected void destroyApp(boolean unconditional)  {

destroyApp() method doesn't throw any exception, then why are you throwing MIDletStateChangeException

Thanks harsh2327, this is a very silly mistake, because i didn't noted that.
Thanks very much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.