Erro "cannot find symbol", como posso resolver? [+Java ME SDK 3.0]

2 respostas
Todi

Olá pessoal,

de antemão peço desculpas por terem outros tópicos, mas creio que o meu seja específico ou deva ser algum bug da JME SDK 3.0!

Enfim, estou criando um joguinho pra celular e uma das classes irá controlar os eventos de objetos interativos ao jogador, no cenário. Segue o código da classe:

package grindgames.mobile;

/**
 *
 * @author Alexandre Ferreira
 */
public class Event {
    private short iID; //ID do evento
    private short iNextEventID; //Evento que será desencadeado ao concluir o atual
    private short iItemNecID; //ID do item necessário para ser concluído este evento
    private short iItemGift; //Item que deverá ser dado ao jogador quando tiver uma missão concluída
    private String strTitle; //Título do evento
    private String strMessage; //Mensagem apresentada ao jogador, com a descrição do evento
    private String strSuccessMsg; //Mensagem de sucesso, quando o evento for concluído
    private String strDefaultMsg; //Mensagem padrão para quando o evento for finalizado e não desencadeará nenhum outro
    private boolean bFinished; //Define quando um evento foi terminado com sucesso
    private boolean bVisible; //Define se o evento é visível para o jogador

    public Event(short iID, short iItemNecID, short iNextEventID, short iItemGift, boolean bVisible, String strTitle, String strMessage,
            String strSuccessMsg, String strDefaultMsg) {
        this.iID = iID;
        this.iItemNecID = iItemNecID;
        this.iNextEventID = iNextEventID;
        this.iItemGift = iItemGift;
        this.bVisible = bVisible;
        this.strTitle = strTitle;
        this.strMessage = strMessage;
        this.strSuccessMsg = strSuccessMsg;
        this.strDefaultMsg = strDefaultMsg;
        this.bFinished = false;
    }

    public short giveGift() {
        if(this.bFinished == true && this.iItemGift > 0) {
            return this.iItemGift;
        }

        return -1;
    }

    public boolean checkItem(short iItemID) {
        if(this.iItemNecID == iItemID) {
            return true;
        }

        return false;
    }

    public String getEventTitle() {
        return this.strTitle;
    }

    public String getEventMessage() {
        return this.strMessage;
    }

    public String getEventSuccessMessage() {
        return this.strSuccessMsg;
    }

    public String getEventDefaultMessage() {
        return this.strDefaultMsg;
    }

    public short getEventItemNec() {
        return this.iItemNecID;
    }

    public short getNextEventID() {
        return this.iNextEventID;
    }

    public short getEventID() {
        return this.iID;
    }

    public boolean isFinished() {
        return this.bFinished;
    }

    public boolean isVisible() {
        return this.bVisible;
    }

    public void setEventTitle(String strTitle) {
        this.strTitle = strTitle;
    }

    public void setEventMessage(String strMessage) {
        this.strMessage = strMessage;
    }

    public void setEventSuccessMessage(String strSuccessMsg) {
        this.strSuccessMsg = strSuccessMsg;
    }

    public void setEventDefaultMessage(String strDefaultMessage) {
        this.strDefaultMsg = strDefaultMessage;
    }

    public void setIsFinished(boolean bFinished) {
        this.bFinished = bFinished;
    }

    public void setIsVisible(boolean bVisible) {
        this.bVisible = bVisible;
    }
}

E aqui a minha midlet:

package grindgames.mobile;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.*;

/**
 * @author Alexandre Ferreira
 */
public class ADayLN extends MIDlet {
    private Display screen;

    public ADayLN() {
        this.screen = Display.getDisplay(this);
    }

    public void startApp() {
        Scene room;
        Event event;
        
        event = new Event(1, -1, 2, -1, true, "Jarro", "Jarro bonito", "Funciona", "Um jarro");
        room = new Scene(loadImage("/bg/room.jpg"));
        room.addEvents(event);
        this.screen.setCurrent(room);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public Image loadImage(String strPath) {
        Image img;

        try {
            img = Image.createImage(strPath);

            return img;
        }
        catch(java.io.IOException error) {
            System.out.println("A imagem não pode ser carregada!");
        }
        catch(NullPointerException error) {
            System.out.println("O caminho da imagem não foi especificado corretamente!");
        }

        return null;
    }
}

E sempre aparece esse erro quando tento compilar:

cannot find symbol
symbol  : constructor Event(int,int,int,int,boolean,java.lang.String,java.lang.String,java.lang.String,java.lang.String)
location: class grindgames.mobile.Event
        event = new Event(1, -1, 2, -1, true, "Jarro", "Jarro bonito", "Funciona", "Um jarro");
1 error

Não sei mais o que fazer para tentar resolver. Já criei um novo projeto, já mudei o nome da classe "Event" para vários outros, já criei uma classe vazia, e sempre ocorre o mesmo erro no construtor. Peço, encarecidamente, que se alguém já passou por isso, por favor, dê-me uma luz!

Agradeço a todos, desde já!

Att.

2 Respostas

luiz_renato

Todi,

No contrutor de Event vc declara 4 parametros do tipo short:
blic Event(short iID, short iItemNecID, short iNextEventID, short iItemGift, boolean bVisible, String strTitle, String strMessage,String strSuccessMsg, String strDefaultMsg) {
Ocorre que quando vc usa esse contrutor vc passar literais inteiras como abaixo:
event = new Event(1, -1, 2, -1, true, "Jarro", "Jarro bonito", "Funciona", "Um jarro");
Mas 1,-1,2,-1 não são short? Somente quando vc usa com variáveis como abaixo ou como resultado de alguma método/operacao
short s1 = 1;
short s2 = -1;
short s3 = 2;
Então ou vc muda os tipos dos parametros do construtor de short p/ int e continua chamando como está ou declara as variáveis como feito acima e chama assim:
Event event = new Event(s1,s2,s3,s2, true, "Jarro", "Jarro bonito", "Funciona", "Um jarro");
Todi
luiz_renato:
Todi, No contrutor de Event vc declara 4 parametros do tipo short:
blic Event(short iID, short iItemNecID, short iNextEventID, short iItemGift, boolean bVisible, String strTitle, String strMessage,String strSuccessMsg, String strDefaultMsg) {
Ocorre que quando vc usa esse contrutor vc passar literais inteiras como abaixo:
event = new Event(1, -1, 2, -1, true, "Jarro", "Jarro bonito", "Funciona", "Um jarro");
Mas 1,-1,2,-1 não são short? Somente quando vc usa com variáveis como abaixo ou como resultado de alguma método/operacao
short s1 = 1;
short s2 = -1;
short s3 = 2;
Então ou vc muda os tipos dos parametros do construtor de short p/ int e continua chamando como está ou declara as variáveis como feito acima e chama assim:
Event event = new Event(s1,s2,s3,s2, true, "Jarro", "Jarro bonito", "Funciona", "Um jarro");

Valeu Renato!
Fiz um typecast e funcionou!

Obrigado!

Criado 14 de novembro de 2011
Ultima resposta 14 de nov. de 2011
Respostas 2
Participantes 2