vendredi 4 août 2023

Public constructor isn't accesible

I have a class with 4 public constructors, but when I try to de-serialize it, it gives me this error:

java.io.InvalidClassException: jzez.Img; no valid constructor

The code of the class:

public class Img extends BufferedImage implements Serializable {

    
    public Img() {
        this(20, 20, 6);
    }
    private static final long serialVersionUID = 1L;

    public Img(int width, int height, int imageType) {
        super(width, height, imageType);
    }

    public Img(int width, int height, int imageType, IndexColorModel cm) {
        super(width, height, imageType, cm);
    }

    public Img(ColorModel cm, WritableRaster raster, boolean isRasterPremultiplied, Hashtable<?, ?> properties) {
        super(cm, raster, isRasterPremultiplied, properties);
    }

    public static Img getImg(BufferedImage bi) {
        ColorModel cm = bi.getColorModel();
        boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
        WritableRaster raster = bi.copyData(null);
        return new Img(cm, raster, isAlphaPremultiplied, null);
    }

}

I made a class that takes a lot of BufferedImages and serializes them. But de-serializing gives an error. I expected it to de-serialize correctly and the constructors to be accesible





Aucun commentaire:

Enregistrer un commentaire