1 Replies - 475 Views - Last Post: 09 August 2009 - 09:25 PM Rate Topic: -----

#1 nathanpc  Icon User is offline

  • SCIENCE!
  • member icon

Reputation: 112
  • View blog
  • Posts: 1,171
  • Joined: 31-July 09

Error When Using a destroyApp(true)

Post icon  Posted 09 August 2009 - 06:36 AM

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

Is This A Good Question/Topic? 0
  • +

Replies To: Error When Using a destroyApp(true)

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Error When Using a destroyApp(true)

Posted 09 August 2009 - 09:25 PM

Dont have microedition but it is because destroyApp() can generate an exception
you will have to

try {
   destroyApp(true);
}
catch(Exception e) {
	System.out.println("destroyApp() failed because: " + e);
	// do something to cath up from that error here
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1