Results 1 to 1 of 1
- 05-23-2009, 12:03 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 11
- Rep Power
- 0
Strange behaviour in serialization
Hi guys,i'm tempting to load a filedata that i serialized before but i obtain a strange behaviour:
I serialized my class that have this constructor:
and this method:Java Code:public ListaRosa() { listaGiocatori = new ListaGiocatori[4]; listaGiocatori[0] = new ListaPortieri(3); listaGiocatori[1] = new ListaDifensori(8); listaGiocatori[2] = new ListaCentrocampisti(8); listaGiocatori[3] = new ListaAttaccanti(6); }
and Listener that work with it are:Java Code:public static ListaRosa caricaListaRosa(){ FileInputStream f = null; ObjectInputStream is = null; ListaRosa listaRosa = null; try { f = new FileInputStream("ListaNomi.dat");//apertura canale stream is = new ObjectInputStream(f); } catch (IOException e1) { System.out.println("File non trovato"); //System.exit(3); } try { listaRosa = (ListaRosa) is.readObject(); is.close(); } catch (Exception e2){ System.out.println(e2.getMessage()+ "Caricamento fallito "+ e2.getCause()); System.exit(4); } return listaRosa; } public void salvaListaRosa(ListaRosa lista){ FileOutputStream f = null; String d; try { d =new String ("ListaNomi.dat"); f = new FileOutputStream(d); } catch(IOException ex) { System.out.println(ex.getMessage() + "Creazione dato fallita" + ex.getCause()); System.exit(1); } ObjectOutputStream os = null; try { os = new ObjectOutputStream(f); os.writeObject(lista); os.flush(); os.close(); } catch (IOException e1) { System.out.println(e1.getMessage() + "Salvataggio fallito" + e1.getCause()); System.exit(2); } }
well i'm no problem when i invoke salvaListaRosa'method with my Listener in GUi,but when i invoke caricaListaRosa instead i just see only 8 names and the item of ComboBox do not displeyd the just item chosen before...Java Code:public class Caricamento implements ActionListener{ private Gestione.ListaRosa listaRosa = new Gestione.ListaRosa(); private final int COMBO_COUNT = 25; private JComboBox[] list = new JComboBox[COMBO_COUNT]; private JTextField[] nGiocatori = new JTextField[COMBO_COUNT]; public Caricamento(JComboBox[] list,JTextField[] nGiocatori){ this.list = list; this.nGiocatori = nGiocatori; } public void actionPerformed(ActionEvent arg0) { try{ Gestione.ListaRosa listaRosaLoaded = Gestione.ListaRosa.caricaListaRosa(); listaRosa = listaRosaLoaded; caricaListaRosaInPannello(); } catch(Exception ex){ System.out.println("Errore nel caricamento della lista rosa..."); return; } } private void caricaListaRosaInPannello(){ for(int i=0; i<listaRosa.getSize(); i++){ Giocatore tmpGiocatore = listaRosa.get(i); nGiocatori[i].setText(tmpGiocatore.getNome()); list[i].setSelectedIndex(tmpGiocatore.getRuolo()); } } } class Salvataggio implements ActionListener{ private Gestione.ListaRosa listaRosa = new Gestione.ListaRosa(); private final int COMBO_COUNT = 25; private JComboBox[] list = new JComboBox[COMBO_COUNT]; private JTextField[] nGiocatori = new JTextField[COMBO_COUNT]; public Salvataggio(JComboBox[] list,JTextField[] nGiocatori){ this.list = list; this.nGiocatori= nGiocatori; } public void actionPerformed(ActionEvent arg0) { for (int i = 0; i < list.length; i++) { String nome = nGiocatori[i].getText(); int ruolo = list[i].getSelectedIndex(); try{ if(nome.equals(" ")){ System.out.println("Giocatore in posizione " + i + " non contiene il nome..."); } listaRosa.addGiocatore(nome, ruolo); } catch(Exception ex1){ System.out.println("Errore costruzione rosa..."); listaRosa = new Gestione.ListaRosa(); return; } } try{ listaRosa.salvaListaRosa(listaRosa); } catch(Exception ex){ System.out.println("Errore in fase di salvataggio rosa..."); return; } }
and i see the message "Errore nel caricamento della lista rosa..."
Same advice?
I should change method serialization?Adapt it to my ListaRosa structure?Last edited by Wolverine; 05-23-2009 at 12:05 PM.
Similar Threads
-
Application freezing and recovering with Strange behaviour found in Thread Dump & GC
By Rajin Das in forum Advanced JavaReplies: 2Last Post: 03-16-2009, 02:33 PM -
Strange behaviour 'DailyRollingFileAppender',two process one log4j configuration file
By yokese in forum New To JavaReplies: 0Last Post: 03-16-2009, 01:41 PM -
Java applet strange painting behaviour
By sirdori in forum New To JavaReplies: 1Last Post: 01-07-2009, 01:14 PM -
AffinedTransform strange behaviour
By Echilon in forum AWT / SwingReplies: 3Last Post: 12-11-2008, 09:58 AM -
Strange behaviour in swing
By cbalu in forum AWT / SwingReplies: 1Last Post: 05-23-2008, 09:23 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks