I am trying to create a sort of simple GUI where im trying to save a couple of Strings and doubles and one int, im using the basic property of OOP which is inheritance I created a class Autos which is essentially the super Class.
The problem seem to arise in a method called "cargarDatosAutos" this is in my GUI class, and here is the code:
private void cargarDatosAutos()
{
regInt = at.numRegistros(); // number of registry
if (regInt != -1)
{
curInt = 0;
ats = new AutosRentables[regInt];
try
{
RandomAccessFile f = new RandomAccessFile("Autos.txt", "rw");
at.cargarDatos(f, ats, regInt); // method in subclass
f.close();
}
catch (IOException ex)
{
Logger.getLogger(Interfaz3.class.getName()).log(Level.SEVERE, null, ex);
}
this.mostrarAutos(ats[0]); // shows data
}
}
Here are the errors:
4-Dec-2011 11:35:20 PM rent_autos.Interfaz3 cargarDatosAutos
SEVERE: null
java.io.EOFException
at java.io.RandomAccessFile.readChar(RandomAccessFile.java:695)
at rent_autos.Autos.leerModelo(Autos.java:139)
at rent_autos.AutosRentables.cargarDatos(AutosRentables.java:84)
at rent_autos.Interfaz3.cargarDatosAutos(Interfaz3.java:6076)
at rent_autos.Interfaz3.<init>(Interfaz3.java:38)
at rent_autos.Interfaz3$159.run(Interfaz3.java:6107)
the leerModelo is a method that reads strings:
public String leerModelo(RandomAccessFile file) throws IOException
{
char cadena[] = new char[25], temp;
for (int c = 0; c < cadena.length; c++)
{
temp = file.readChar();
cadena[c] = temp;
}
return new String(cadena).replace('\0', ' ');
}
And the cargarDatos is to load my data:
public void cargarDatos(RandomAccessFile file, AutosRentables[] lista, int reg) throws IOException
{
int cont = 0;
do
{
modelo = this.leerModelo(file);
color = this.leerColor(file);
tipoAM = this.leerTipoAM(file);
rendimientoGalon = file.readDouble();
placa = this.leerPlaca(file);
ACRISS = this.leerACRISS(file);
codigo = file.readInt();
costo = file.readDouble();
marca = this.leerMarca(file);
detalles = this.leerDetalles(file);
lista[cont] = new AutosRentables(modelo, color, tipoAM, rendimientoGalon, placa, ACRISS, codigo, costo, marca, detalles);
cont++;
System.out.println("Entra");
}
while (cont < reg);
}
And heres the ArrayoutOfbound error:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at rent_autos.Interfaz3.cargarDatosAutos(Interfaz3.java:6081)
at rent_autos.Interfaz3.<init>(Interfaz3.java:38)
at rent_autos.Interfaz3$159.run(Interfaz3.java:6107)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
So if anyone knows whats going on please help me out here... is it the byte size of the file?, I really dont know, HELP!