Consultar não está dando certo

ai galera consegui fazer o cadastrar, listar e o alterar,mas não estou conseguindo fazer o consultar,aki em baixo está o código do consultar,deem uma olhada ai pra mim,pra ver se descobre aonde q estou errando…Agradeço desde já …

public void commandAction(Command C, Displayable D) {

	if(C == sair){
		notifyDestroyed();
	}
	if(C == cadastrar){
		try {
			
			rs=RecordStore.openRecordStore("Universidade", true);
			byte bnome[]= (nome.getString()).getBytes();
			byte bmatricula[] = (matricula.getString()).getBytes();
			byte bcurso[]=curso.getString(curso.getSelectedIndex()).getBytes();
			rs.addRecord(bnome, 0, bnome.length);
			rs.addRecord(bmatricula, 0, bmatricula.length);
			rs.addRecord(bcurso, 0, bcurso.length);
			
			Alert mensagem = new Alert("Cadastrado","Aluno inserido com sucesso",null,null);
			mensagem.setTimeout(2000);
			tela.setCurrent(mensagem);
			
			nome.setString("");
			matricula.setString("");
			
			rs.closeRecordStore();
			}
			catch(Exception e){
		}
	
	}
	 	if(C == listar){
			String aux = "";
			try {
				rs = RecordStore.openRecordStore("Universidade", true);
				for(int i=1;i < rs.getNextRecordID();i+=3){
					String lnome = new String(rs.getRecord(i));
					String lmatricula = new String(rs.getRecord(i+1));
					String lcurso = new String(rs.getRecord(i+2));
					
					aux = aux +"Nome:"+lnome + "Matricula:"+lmatricula+ "Curso:"+lcurso ;
				}
					rs.closeRecordStore();
					Alert msg = new Alert("Lista",aux, null , AlertType.INFO);
					msg.setTimeout(3000);
					tela.setCurrent(msg);
				
			
			}
			catch(Exception e){
			}	
			}
	 	if(C == alterar){
	 		String aux = "";
	 		try { 
	 			rs=RecordStore.openRecordStore("Universidade", true);
	 			for(int i=1;i < rs.getNextRecordID();i+=3){
	 				
	 				String busnome = new String (rs.getRecord(i));
	 				
	 				if(busnome.equals(nome.getString())){
	 					
	 					byte bnome[] = (nome.getString()).getBytes();
	 					byte bmatricula[] = (matricula.getString()).getBytes();
	 					byte bcurso[] = (curso.getString(curso.getSelectedIndex()).getBytes());
	 					
	 					rs.setRecord(i, bnome, 0, bnome.length);
	 					rs.setRecord(i+1, bmatricula, 0, bmatricula.length);
	 					rs.setRecord(i+2,bcurso,0,bcurso.length);
	 					
	 					aux = aux +"nome:"+bnome+"\nmatrícula"+bmatricula+"\nCurso:"+bcurso;
	 				}
	 			}
	 			
	 			rs.closeRecordStore();
	 			Alert alt = new Alert("Alterar","Registro alterado com sucesso",null,AlertType.INFO);
	 			alt.setTimeout(3000);
	 			tela.setCurrent(alt);
	 		}catch (Exception e){
	 			
	 		}
	 		
	 	}
	 	if(C == consultar){
	 		String aux = "";
	 		try {
	 			rs = RecordStore.openRecordStore("Universidade", true);
	 			
						
	 			for(int i = 1;i<rs.getNextRecordID();i+=3){
	 				
	 				byte bnome[] = (nome.getString()).getBytes();
 					byte bmatricula[] = (matricula.getString()).getBytes();
 					byte bcurso[] = (curso.getString(curso.getSelectedIndex()).getBytes());
	 				
	 			
	 				String buscarNome = new String(rs.getRecord(i));
	 				
	 				if(buscarNome.equals(nome.getString())){
	 					
	 					rs.getRecord(i, bnome,bnome.length);
	 					rs.getRecord(i+1,bmatricula,bmatricula.length);
	 					rs.getRecord(i+2,bcurso,bcurso.length);
	 					
	 					aux = aux + "\nNome: "+bnome+"\nMatricula: "+bmatricula+"\nCurso: "+bcurso;
	 					
	 					Alert msg = new Alert("Consulta",aux,null,null);
	 					msg.setTimeout(3000);
	 					tela.setCurrent(msg);
	 					
	 				}
	 			
	 			}	
	 			
	 			}
	 			
	 				
	 			
	 			catch (Exception e){
	 	}
		
	}
}

}

pra ficar mais legivel

public void commandAction(Command C, Displayable D) {

if(C == sair){
notifyDestroyed();
}
if(C == cadastrar){
try {

rs=RecordStore.openRecordStore("Universidade", true);
byte bnome[]= (nome.getString()).getBytes();
byte bmatricula[] = (matricula.getString()).getBytes();
byte bcurso[]=curso.getString(curso.getSelectedIndex()).getBytes();
rs.addRecord(bnome, 0, bnome.length);
rs.addRecord(bmatricula, 0, bmatricula.length);
rs.addRecord(bcurso, 0, bcurso.length);

Alert mensagem = new Alert("Cadastrado","Aluno inserido com sucesso",null,null);
mensagem.setTimeout(2000);
tela.setCurrent(mensagem);

nome.setString("");
matricula.setString("");

rs.closeRecordStore();
}
catch(Exception e){
}

}
if(C == listar){
String aux = "";
try {
rs = RecordStore.openRecordStore("Universidade", true);
for(int i=1;i < rs.getNextRecordID();i+=3){
String lnome = new String(rs.getRecord(i));
String lmatricula = new String(rs.getRecord(i+1));
String lcurso = new String(rs.getRecord(i+2));

aux = aux +"Nome:"+lnome + "Matricula:"+lmatricula+ "Curso:"+lcurso ;
}
rs.closeRecordStore();
Alert msg = new Alert("Lista",aux, null , AlertType.INFO);
msg.setTimeout(3000);
tela.setCurrent(msg);


}
catch(Exception e){
}
}
if(C == alterar){
String aux = "";
try {
rs=RecordStore.openRecordStore("Universidade", true);
for(int i=1;i < rs.getNextRecordID();i+=3){

String busnome = new String (rs.getRecord(i));

if(busnome.equals(nome.getString())){

byte bnome[] = (nome.getString()).getBytes();
byte bmatricula[] = (matricula.getString()).getBytes();
byte bcurso[] = (curso.getString(curso.getSelectedIndex()).getBytes());

rs.setRecord(i, bnome, 0, bnome.length);
rs.setRecord(i+1, bmatricula, 0, bmatricula.length);
rs.setRecord(i+2,bcurso,0,bcurso.length);

aux = aux +"nome:"+bnome+"\nmatrícula"+bmatricula+"\nCurso:"+bcurso;
}
}

rs.closeRecordStore();
Alert alt = new Alert("Alterar","Registro alterado com sucesso",null,AlertType.INFO);
alt.setTimeout(3000);
tela.setCurrent(alt);
}catch (Exception e){

}

}
if(C == consultar){
String aux = "";
try {
rs = RecordStore.openRecordStore("Universidade", true);


for(int i = 1;i<rs.getNextRecordID();i+=3){

byte bnome[] = (nome.getString()).getBytes();
byte bmatricula[] = (matricula.getString()).getBytes();
byte bcurso[] = (curso.getString(curso.getSelectedIndex()).getBytes());


String buscarNome = new String(rs.getRecord(i));

if(buscarNome.equals(nome.getString())){

rs.getRecord(i, bnome,bnome.length);
rs.getRecord(i+1,bmatricula,bmatricula.length);
rs.getRecord(i+2,bcurso,bcurso.length);

aux = aux + "\nNome: "+bnome+"\nMatricula: "+bmatricula+"\nCurso: "+bcurso;

Alert msg = new Alert("Consulta",aux,null,null);
msg.setTimeout(3000);
tela.setCurrent(msg);

}

}

}



catch (Exception e){
}

}
}
} 

da algum erro? tenta usar o equalsIgnoreCase ou StartWhith…

se der algum erro posta ai pra gente…

mais uma coisa…

lhe aconselharia a usar o floggy…um framewirk bem facil de usar e que abstrai toda essa complexidade do RS…ja usei e aconselho…:wink:

Não dá erro nenhum acontece q quando eu clico em consultar no menu,não acontece nada, mas a ação do botão está implementada certinha,de uma olhada ai só,e já tentei com equalsIgnoreCase e também não deu certo…
Nunca usei esse floggy mas depois q terminarem minhas provas vou começa-lo a vê-lo pra ver como q é,eu tenho q fazer esse programa,pois minha prova exigirá rms(cadastrar,alterar,listar,excluir e consultar).
vc tem outra solução para o meu programa,o q pode está causando a não ação do botão consultar…
e me diz uma outra coisa,como q eh o processo de debugar no eclipse Me ???

he mano agora pegou…pq tb nao sabemo se podes usar o floggy, mas se sim…eu te dou uma força…olha so o codigo de inclusao em RMS com floggy.

public void salvar(FuncionarioRms func){
        
        PersistableManager pm = PersistableManager.getInstance();
        
        try{
            pm.save(func);
        }catch(FloggyException e){
            
        }
    }

http://floggy.sourceforge.net/

a sacada é q ele salva o objeto…vc nao precisa se preocupar com nada de byte nem posição ele faz tudo isso pra tu…tu é bem mais simples…se vc demorou 1 dia pra fazer esse ai…com o floggy vc vai demorar 2h :wink:

tem um tuto que ensina a configurar no eclipse…

voltando ao seu propblema…zipa ai o codigo e anexa aqui e manda…

po bem trankilo mesmo esse floggy,mas a principio eu tenho q resolver este problema aki …estou com o projeto zipado aki como q faço para mandar pra vc …não estou achando o anexar …

manda pro meu e-mail…

fala amigo já te mandei o projeto por email,valeu???
Abraço

so passando olho…vi que tem um erro de logica no seu codigo…

vc faz

String aux = "";

//depois

Alert msg = new Alert("Consulta",aux,null,null);

//e por ultimo

aux = aux + "\nNome: "+bnome+"\nMatricula: "+bmatricula+"\nCurso: "+bcurso;

como ele vai exibir o nome se ao chamar o metodo vc seta aux “” exibe aux vazio e so depois preenche?

acho que é isso…

vou olhar mais aqui…qualquer coisa ter aviso…

pode cre,o aux esta vazio eu fiz ao contrario e nem tinha percebido,mas inverti e coloquei certo agora,mas mesmo assim a acão ao clicar em consultar não existe …de só uma olhada …

caro gafanhoto…um conselho…nao retire das clausulas cacth os e.printStackTrace(); pois eles ajudam muito…

aqui esta…consultando bonitinho… :wink:

if (C == consultar) {
            String aux = "";
            try {
                rs = RecordStore.openRecordStore("Universidade", true);


                for (int i = 1; i < rs.getNextRecordID(); i += 3) {
                    String bnome = new String(rs.getRecord(i));
                    String bmatricula = new String(rs.getRecord(i + 1));
                    String bcurso = new String(rs.getRecord(i + 2));

                    System.out.println(bnome);

                    if (bnome.equalsIgnoreCase(nome.getString())) {

                        rs.getRecord(i);
                        rs.getRecord(i + 1);
                        rs.getRecord(i + 2);

                        Alert msg = new Alert("Consulta", aux, null, null);
                        msg.setTimeout(3000);
                        tela.setCurrent(msg);
                        aux = aux + "\nNome: " + bnome + "\nMatricula: " + bmatricula + "\nCurso: " + bcurso;




                    }
                }
                rs.closeRecordStore();




            } catch (Exception e) {
                e.printStackTrace();
            }

        }

tenta mudar o nome desse topico, acrescenta J2ME pra ficar facil de identificar qaundo outras pessoas veirem com essa mesma duvida :wink:

boa sorte…

usa o floggy

grande obrigado por ter analisado o codigo,mas quando vou rodar continua não acontecendo nada …e botei pra debugar e acusou esse erros no console:

Connecting to 127.0.0.1 on port 2800
Waiting for debugger on port 55363
Waiting for KVM…
Connection received.
Running with storage root C:\Users\leoojas\j2mewtk\2.5.2\appdb\temp.DefaultColorPhone77
Running with locale: Portuguese_Brazil.1252
Running in the identified_third_party security domain
Connected to KVM
java.lang.NullPointerException
at java.lang.String.(+4)
at Aluno.commandAction(+291)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)

tem idéia do q seja ?
valeu …

Consegui abel,mas só q ele consegue realizar a consulta do primeiro elemento da lista…se for do segundo ele já não tras o registro…ver no teu ai pra ver se acontece isso…

cara ai é logica…da um olhada nessa logica ai…deve ser algo naquele for :slight_smile:

exatamente isso q vc falou…(o problema estava no for,e tinha acrescentado mais um campo idade,e não tinha colocado na incrementação do for +1)po kra não sei como te agradecer …muito obrigado mesmo ,desculpa pela noobisse …
agora vou fazer o excluir …

Amigo to tentando fazer o excluir e só falta esse pra eu terminar o rms e fazer uma prova trankila,olha só o q está acontecendo, quando clico no botão excluir ele chega até a mensagem do alert, indicando q o aluno foi removido,mas depois quando eu clico na opção listar do menu, não acontece nada …o botão fica sem sua ação.aki está o excluir…

if(C == excluir){
try {
rs = RecordStore.openRecordStore(“Universidade”, true);

	 			for(int i = 1;i<rs.getNextRecordID();i+=4){
	 				
	 				String bnome = new String(rs.getRecord(i));  
                        
                        
	 				if(bnome.equals(nome.getString())){
	 					
	 					rs.deleteRecord(i);
	 					rs.deleteRecord(i + 1);
	 					rs.deleteRecord(i + 2);
	 					rs.deleteRecord(i + 3 );
	 					
	 					Alert msg = new Alert("Remoção","Aluno Removido com sucesso",null,null);
	 					msg.setTimeout(3000);
	 					tela.setCurrent(msg);
	 				
	 					
	 				}
	 				
	 			}
	 			rs.closeRecordStore();
	 		}
	 		catch (Exception e ){
	 			e.printStackTrace();
	 	}
	 	}

cara isso tb é logica…coloca uns systemout la no listar pra vc saber oqe esta ocorrendo…coloca no excluir tb…pra v se ta excluindo relamente so 1…ou se esta excluindo o rs…

Está removendo sim,no System.out.println mostra q está excluindo(um registro só) mas só q quando vou listar pelo menu ele não lista mais.Então quando coloco pra listar de novo,aparece isso no console…

javax.microedition.rms.InvalidRecordIDException
at javax.microedition.rms.RecordStore.findRecord(+98)
at javax.microedition.rms.RecordStore.getRecord(+22)
at Aluno.commandAction(+545)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)

é pq ele ta tentando pegar o registro que foi excluido…acho que vc tem que fechar o rms ou de alguma maneira atualizar…para que o resto do programa saibaq ue foi algo removido…

Aproveitando gostaria de fazer outra pergunta pra vc …pois pode cair na minha prova d hoje,eh em relação a persistir um choiceGroup Multiplo,qual seria o metodo que utilizaria para pegar o conteudo??