ciao a tutti, ho un problema con una classe, non riesco a serializzarla: quando viene invocato il metodo di deserializzazione mi lancia notSerializableExcpetion.
La classe grossomodo è la seguente:
public class Categoria implements Serializable {
non riesco a trovare l'errore, gli uniche due variabili non static sono un oggetto String e una LinkedList di Coordinate, entrambe Serializablecodice:private String nome; private LinkedList<Coordinate> posizioni; private static LinkedList<Categoria> categorieCustom = new LinkedList<Categoria>(); private static Categoria[] categorieDefault = ... private static final String[] CATEGORIE_PREINIT = ... private Categoria(String nome){ this.nome = nome; } public Categoria(String nome, LinkedList<Coordinate> posizioni){ this.nome = nome; this.posizioni = posizioni; categorieCustom.add(this); salva();//salva le categorie su file } private void salva(){ ObjectOutputStream out = null; try { FileOutputStream fileOut = new FileOutputStream("catcustom.bin"); out = new ObjectOutputStream(fileOut); out.writeObject(categorieCustom); } catch (IOException ex) { Logger.getLogger(Categoria.class.getName()).log(Level.SEVERE, null, ex); } finally { try { out.close(); } catch (IOException ex) { Logger.getLogger(Categoria.class.getName()).log(Level.SEVERE, null, ex); } } } public static void caricaCategorie(){ ObjectInputStream in = null; try { FileInputStream fileIn = new FileInputStream("catcustom.bin"); in = new ObjectInputStream(fileIn); try { categorieCustom = (LinkedList<Categoria>) in.readObject(); } catch (ClassNotFoundException ex) { Logger.getLogger(Categoria.class.getName()).log(Level.SEVERE, null, ex); } } catch (IOException ex) { Logger.getLogger(Categoria.class.getName()).log(Level.SEVERE, null, ex); } finally { try { in.close(); } catch (IOException ex) { Logger.getLogger(Categoria.class.getName()).log(Level.SEVERE, null, ex); } } } /*vari metodo tostring, get, e set... */

Rispondi quotando