Original Post
Hey guys. I'm having some trouble using the command listener. I implemented the following main class:
[sourcecode=javax]
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class MainBase extends MIDlet implements Runnable, CommandListener
{
private Display desplegar;
private Command comandoSalir;//Comando de Salida
private GameAlfaClass program;
public int opcion=99;
public boolean isPlay=true;
public boolean isOut=true;
public void startApp() throws MIDletStateChangeException
{
desplegar = Display.getDisplay(this);
program=new GameAlfaClass(this);
comandoSalir = new Command("Salir",Command.EXIT,1);
program.addCommand(comandoSalir);
program.setCommandListener(this);
Thread t = new Thread(this);
t.start();
}
public void run()
{
try
{
program.start();
desplegar.setCurrent(program);
isOut = true;
while (isOut){}
program.stop();
program = null;
}
catch (Exception ex)
{
System.out.println(ex);
notifyDestroyed();
}
}
public Display getDisplay()
{
return desplegar;
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void commandAction(Command c, Displayable s)
{
if (c == comandoSalir)
{
destroyApp(true);
notifyDestroyed();
}
}
}
[/sourcecode]
The GAMEALFACLASS works like this:
public class GameAlfaClass extends GameCanvas implements Runnable
======================
The problem comes when i run this app on my Nokia 6670. When i use the command "comandoSalir", i get this two errors:
1) Buffer closed java.lang.RunTimeException !
2) 0 java.lang.NullPointerException !
Anyone knows something about this?
Thanks