Sou iniciante em J2ME e estou tentando carregar uma imagem para minha midlet e não estou conseguindo. Estou utilizando o eclipse. Tbem ja tentei compilar o codigo atraves do WTK, colocando a imagem no ‘res’ e não consegui carregar a imagem.
Se puderem me ajudar…
Meu codigo.
package ImutableImage;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ImutableImage extends MIDlet implements CommandListener{
private Display display;
private Form form;
private Command exit;
private Image image;
private ImageItem imageItem;
public ImutableImage(){
display = Display.getDisplay(this);
exit = new Command("Sair",Command.EXIT,1);
form = new Form("Imagem imutavel");
form.addCommand(exit);
form.setCommandListener(this);
try{
image = Image.createImage("/imagem.png");
imageItem = new ImageItem(null, image, ImageItem.LAYOUT_NEWLINE_BEFORE |
ImageItem.LAYOUT_LEFT | ImageItem.LAYOUT_NEWLINE_AFTER,
"minha imagem");
form.append(imageItem);
}catch(java.io.IOException error){
Alert alert = new Alert("Erro", "Não foi possivel carregar a imagem",null,null);
alert.setTimeout(Alert.FOREVER | 100);
alert.setType(AlertType.ERROR);
display.setCurrent(alert);
}
}
protected void startApp() {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void destroyApp(boolean arg0) {
// TODO Auto-generated method stub
}
public void commandAction (Command command, Displayable displayable){
if (command == exit){
destroyApp(true);
notifyDestroyed();
}
}
}