Boa noite,
estou com outra duvida pessoal:
to fazendo uma agenda (hehe, todo iniciante faz :D), mas estou com problemas com a serializacao… meu metodo eh o seguinte:
public void salvar(){
String filename = "agenda.dat";
try{
File file = new File(filename);
if (!file.exists()){
file.createNewFile();
}
OutputStream out = new FileOutputStream(file);
ObjectOutputStream saida = new ObjectOutputStream(out);
this.listar();
saida.writeObject(this.ag);
saida.flush();
}
catch(NotSerializableException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
sendo que ‘ag’ eh um objeto do tipo agenda, e nao esta vazio (ateh tem this.listar() ali pq tava testando isso)… mas sempre da erro na linha “saida.writeObject(this.ag)”… a msg eh a seguinte:
java.io.NotSerializableException: Agenda
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
at AgendaTexto.salvar(AgendaTexto.java:156)
at AgendaTexto.verMudanca(AgendaTexto.java:207)
at AgendaTexto.main(AgendaTexto.java:266)
LINHA 156 => saida.write…
LINHA 207 => lugar onde chamo o metodo salvar()
LINHA 266 => linha onde eh chamado o metodo que chama o salvar()
nao sei se ficou meio confuso… mas se alguem puder me ajudar agradeco.
Valeu