No valid constructor during serialization

前端 未结 2 1726
逝去的感伤
逝去的感伤 2021-01-13 03:39

I have a major problem during loading the extension into the program. I get an exception as there is no valid constructor.

The problem is in the line:

相关标签:
2条回答
  • 2021-01-13 04:11

    As specified in Oracle site about Serialization interface :

    During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream.

    What I gues is that Dydaktyk is the subclass of some class. And you have defined the parametric constructor within the superclass and have not defined a parameter-less constructor within it . And the compiler isn't inserting a default constructor for that superclass. So , You should define a parameter-less constructor within your superclass also.

    0 讨论(0)
  • 2021-01-13 04:12

    The class Dydaktyk should have an accessible (public or protected) no-args constructor so that the serialization reflection mechanism can create an instance of the class:

    public Dydaktyk() { 
      ...
    }
    

    From the docs

    During deserialization, the fields of non-serializable classes will be initialized using the public or protected no-arg constructor of the class. A no-arg constructor must be accessible to the subclass that is serializable. The fields of serializable subclasses will be restored from the stream.

    0 讨论(0)
提交回复
热议问题