継承であるOOPの基本プロパティを使用して、本質的にスーパークラスであるクラスAutosを作成しました。
「cargarDatosAutos」と呼ばれるメソッドで問題が発生したようです。これは私の GUI クラスにあり、コードは次のとおりです。
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
}
}
エラーは次のとおりです。
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)
leerModelo は、文字列を読み取るメソッドです。
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', ' ');
}
そして cargarDatos は私のデータをロードすることです:
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);
}
ArrayoutOfbound エラーは次のとおりです。
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)
それで、誰かが何が起こっているか知っているなら、ここで私を助けてください...それはファイルのバイトサイズですか?、私は本当に知りません、助けて!