I've burned my neurons trying to fix this, if anyone can give a help; It follows the code that the error occurs. I'm trying to open subclasses that have been serialized, but this error does not know why.
try{
fileInput = new FileInputStream("C:\Users\Trojers\Documents\NetBeansProjects\Trabalho\trabalho.txt");
ObjectInputStream ler = new ObjectInputStream(fileInput);
while(true){
ArrayList<Aluno> al = (ArrayList)ler.readObject();
ler.close();
System.out.print(al);
}
} catch (FileNotFoundException ex) {
System.out.printf("Nao encontrado");
System.exit(0);
} catch (IOException ex) {
ex.printStackTrace();
} catch (ClassNotFoundException ex) {
System.out.printf("Nao encontrado.\n");
System.exit(0);
}
StrackTrace:
java.io.StreamCorruptedException: invalid type code: AC
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1563)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
at trabalho.Interface.imprimir_TodosAlunos(Interface.java:201)
at trabalho.Interface.mostrar_Dados(Interface.java:292)
at trabalho.Interface.tela(Interface.java:54)
at trabalho.Trabalho.main(Trabalho.java:18)
The serialization of objects was done like this:
//Inicializacao dos atributos
Aluno ob = new Pos_Graduacao_Aluno(nome, sobrenome, rga, nomeCurso,
ano_Ingresso, nome_Orient, sob_Nome, nota_Exame); //Aqui, instancio um
objeto do tipo Pos_Graduacao_Aluno, que extende de aluno
cadastrar(ob); //Metodo responsavel por colocar no ArrayList
tela();
} catch(InputMismatchException ex){
System.out.printf("Valor incorreto.\n");
tela();
}
public void cadastrar(Aluno e){ //Metodo que insere no ArrayList
try {
objectOutput = new ObjectOutputStream(fileOutput);
objectOutput.writeObject(e);
} catch (IOException ex) {
System.out.printf("Nao foi possivel salvar o arquivo.\n");
}
}