javaserializationnotserializableexception

java.io.NotSerializableException: javax.swing.GroupLayout


I have this code and it throws the exception

java.io.NotSerializableException: javax.swing.GroupLayout

The code is the following

package basededatosmuebleria;
import FrontEnd.VentanaIngresoMedianteArchivo;
import java.io.*;
import javax.swing.JOptionPane;

public class FileController implements Serializable {
    public static void escribirObjetoPieza(String nombre, Pieza pieza){
        try{
            ObjectOutputStream fileOut = new ObjectOutputStream(
        new FileOutputStream(nombre));
        fileOut.writeObject(pieza);
        fileOut.close();
        }
        catch (IOException e){ 
            JOptionPane.showMessageDialog(null, e);
        }
    }
}

The class that sends invokes the method is the following ...

package basededatosmuebleria;
import FrontEnd.VentanaIngresoMedianteArchivo;
import static java.lang.Double.parseDouble;
import java.util.StringTokenizer;
import java.io.*;

public class Pieza implements Serializable {
    String tipo;
    double costo;
    VentanaIngresoMedianteArchivo comunicador = new                     
    VentanaIngresoMedianteArchivo();
    public Pieza(String tipo, double costo){
        this.tipo=tipo;
        this.costo=costo;
    }
    public Pieza(){}
    public String getTipo(){
        return this.tipo;
    }
    public double getCostoPieza(){
        return this.costo;
    }
    public void evaluarLinea(String line) {
            try{
            StringTokenizer token = new StringTokenizer(line,",");
            tipo=token.nextToken()
                    .replaceAll("PIEZA", "")
                    .replace("(", "")
                    .replaceAll("\"","");
            costo=parseDouble(token.nextToken()
                    .replace(")",""));
            Pieza pieza = new Pieza (tipo, costo);
            int contador = FileController.leerContadorPiezas(tipo);
            String nombreDelObjeto=
                    "Pieza"
                    +tipo
                    +String.valueOf(contador)
                    +".dat";
            FileController.escribirObjetoPieza(nombreDelObjeto, pieza);   
        }
        catch(NullPointerException e){
            VentanaIngresoMedianteArchivo.cajaDeMensajes.append("No se ha ingresado un valor en el precio de la pieza");
        }
        catch(NumberFormatException e){
            VentanaIngresoMedianteArchivo.cajaDeMensajes.append("El formato ingresado es incorrecto. no es un numero real");
        }
    }  
}

Solution

  • As the exception message states, javax.swing.GroupLayout is not serialisable.

    What to do?

    Your favourite Java Serialisation reference should give you the options in this case. Briefly your choices are: