Reputation:
I have a method to go a randomaccesFile, when registering keep a char "A" if it is active and "B" if not, then an int with the number of bytes in the record and then register as such. what happens when a code is equal to that method give way to return true; but in the end I returns false
public boolean seEncuentra(int pos , char[] codigo) {
clsPersona contacto = new clsPersona(); //object contact
try {
// buscar registro apropiado en el archivo
abrirArchivo();
archivo.seek(pos);
contacto.estado = archivo.readUTF();
contacto.setTAMANIO(archivo.readInt());
if("A".equals(contacto.estado))
{
for (int i = 0; i < 3; i++) {
contacto.codigo[i] = archivo.readChar();
}
if(Arrays.equals(codigo, contacto.codigo))
{
return true; //enter here and ends up returning false at the end
}
else
{
pos+=contacto.TAMANIO;
seEncuentra(pos, codigo);
}
}
else
{
pos+=contacto.TAMANIO;
seEncuentra(pos, codigo);
}
cerrarArchivo();
}
catch (Exception ex) {
System.out.println(ex.getMessage());
ex.printStackTrace();
cerrarArchivo();
return false;
}
return false;
}
Upvotes: 1
Views: 114
Reputation: 201447
You recurse without returning the value recursed. Change
seEncuentra(pos, codigo);
to
return seEncuentra(pos, codigo);
in every place you recurse.
Upvotes: 4