Boa noite a todos.
Estou com um erro em uma aplicação que estou fazendo. Não consigo encontrar o que é este erro.
Estou postando as minhas classes e o erro gerado para que possam me ajudar a descobrir. Provavelmente o erro deve estar muito claro, mas devo ter viciado no código e não
consigo encontrar, ao menos assim espero.
[MidletController]
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class MidletController extends MIDlet implements CommandListener{
Display display;
Form formImagem;
Command mInsertCommand, mExitCommand;
public MidletController(){
formImagem= new Form("Se7en App");
Image img = null;
try{
img = Image.createImage("/seven.png");
ImageItem imagem = new ImageItem("", img, ImageItem.LAYOUT_CENTER, "Alt Text" );
formImagem.append(imagem);
}
catch(Exception e){
//mensagem de erro
}
mInsertCommand = new Command("Cadastro", Command.SCREEN, 0);
mExitCommand = new Command("Sair", Command.EXIT, 0);
formImagem.addCommand(mInsertCommand);
formImagem.addCommand(mExitCommand);
formImagem.setCommandListener(this);
}
public void startApp() {
display = Display.getDisplay(this);
display.setCurrent(formImagem);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void mudarTela(Displayable d){
this.display.setCurrent(d);
}
public void commandAction(Command c, Displayable d) {
if(c.getCommandType() == Command.EXIT){
destroyApp(true);
notifyDestroyed();
}else if(c == mInsertCommand){
mudarTela(new MidletForm().getForm());
}
}
}
[MidletForm]
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import javax.microedition.lcdui.*;
public class MidletForm extends Form implements CommandListener{
private Command mSaveCommand, mListCommand, mExitCommand;
private MidletController controller;
private TextField mId, mNome;
private StringItem mProgressString;
public MidletForm(){
super("Formulário");
mSaveCommand = new Command("Salvar", Command.OK, 0);
mListCommand = new Command("Listar", Command.SCREEN, 0);
mExitCommand = new Command("Sair", Command.EXIT, 0);
addCommand(mSaveCommand);
addCommand(mListCommand);
addCommand(mExitCommand);
mId = new TextField("Código", null, 4, TextField.NUMERIC);
mNome = new TextField("Nome", null, 100, TextField.ANY);
append(mId);
append(mNome);
append(mProgressString);
setCommandListener(this);
}
public void commandAction(Command c, Displayable d) {
}
public void salvar(){
HttpConnection hc = null;
InputStream is = null;
String url = "http://localhost/J2ME_Servlet/InserirPessoa?id="+mId.getString()+"&nome="+mNome.getString();
mProgressString.setText("Conectando...");
System.out.println("URL = "+url);
try {
hc = (HttpConnection) Connector.open(url);
hc.setRequestMethod(HttpConnection.GET);
hc.setRequestProperty("User-Agent", "Profile/MIDP-2.1 Configuration/CLDC-1.0");
hc.setRequestProperty("Content-Language", "en-US");
is = hc.openDataInputStream();
} catch (IOException e) {
System.out.println("Erro: " + e.getMessage().toString());
}
}
public Form getForm(){
return this;
}
}
Erro ao chamar o mInsertCommand.
TRACE: <at java.lang.NullPointerException: 0>, Exception caught in Display class
java.lang.NullPointerException: 0
at javax.microedition.lcdui.Form.append(), bci=7
at MidletForm.<init>(), bci=132
at MidletController.commandAction(MidletController.java:52)
at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
at com.sun.midp.chameleon.layers.SoftButtonLayer.soft2(), bci=173
at com.sun.midp.chameleon.layers.SoftButtonLayer.softPress(), bci=36
at com.sun.midp.chameleon.layers.SoftButtonLayer.pointerInput(), bci=142
at com.sun.midp.chameleon.CWindow.pointerInput(), bci=76
at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handlePointerEvent(), bci=19
at com.sun.midp.lcdui.DisplayEventListener.process(), bci=296
at com.sun.midp.events.EventQueue.run(), bci=179
at java.lang.Thread.run(Thread.java:662)
Agradeço as respostas.