Programación General > Java

 Error con archivos y ArrayList

(1/1)

tomas_sauron:
hola gente!!! estoy empezando en java hace un mes y algo mas y leyendo un poco logre llegar  hasta archivos en mi entendimiento pero m falta mucho todavia.Bueno la cosa es esta , tengo problemas con este codigo estoy intentando a hacer una especie d agenda pero lo unico q m importa ees ver el funcionamiento de archivos y ArrayList y su relacion el programa esta hecho en netbeans 6.9
y el problema salta cuando quiero leer el archivo paara mostrar los datos al guardar no hay problema el error qu tira es en tiempo d ejecucion y es est [color=#FF0000Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException]
aqui el codigo del boton q abre los datos
--- Código: Java --- private void btnSavePerson1ActionPerformed(java.awt.event.ActionEvent evt) {       try{          ObjectInputStream fileIn=new ObjectInputStream(new FileInputStream("agenda.dat"));            try {                book = (ArrayList) fileIn.readObject();            } catch (ClassNotFoundException ex) {                Logger.getLogger(Formulario.class.getName()).log(Level.SEVERE, null, ex);            }          fileIn.close();         Datos agenda=book.get(i-1);         nom=agenda.getNombre();         ape=agenda.getApellido();         dir=agenda.getDireccion();         mail=agenda.getEmail();         tel=agenda.getTelefono();         txtName1.setText(nom);         txtApe1.setText(ape);         txtDire1.setText(dir);         txtmail1.setText(mail);         txtTel1.setText(""+tel);      }catch(FileNotFoundException ex){          JOptionPane.showMessageDialog(this,"Error!! No se encuentra archivo");       }catch(IOException ex){          JOptionPane.showMessageDialog(this,"Error!!");       }      }  y el boton qu guarda es este
--- Código: Java --- private void btnSavePersonActionPerformed(java.awt.event.ActionEvent evt) {            ape=txtApe.getText();           nom=txtName.getText();           dir=txtDire.getText();           mail=txtmail.getText();           tel=Integer.parseInt(txtTel.getText());           Datos agenda = new Datos(nom,ape,mail,dir,tel);           book.add(i,agenda);           i++;           txtApe.setText("");           txtName.setText("");           txtDire.setText("");           txtmail.setText("");           txtTel.setText("");            try{               ObjectOutputStream fileOut=new ObjectOutputStream(new FileOutputStream("agenda.dat"));               fileOut.writeObject(agenda);               fileOut.close();           }catch(FileNotFoundException ex){               JOptionPane.showMessageDialog(this,"Error!! No se encuentra archivo");           }catch(IOException ex){              JOptionPane.showMessageDialog(this,"Error!!");             }      } PD: hay una cclase Datos q possee todos los geters y seters con los atributos nombre apellido direccion email y telefono si alguien m puede contestar se lo agradecere mucho !!!!!!!!!!!!


[/color]

Navegación

[0] Índice de Mensajes

Ir a la versión completa