NotSerializableException on SimpleListProperty

后端 未结 6 1905
予麋鹿
予麋鹿 2020-12-10 08:09

I\'m using Javafx, and I wrap my objects into ListProperty to let the tableview updates for any changes on the objects of the list. Now I\'m trying to serialize my project a

6条回答
  •  旧时难觅i
    2020-12-10 08:58

    To avoid NotSerializableException make sure:

    1. your class implements Serializable
    2. all non primitive members implement Serializable (or are transient instead)
    3. if your class is an inner class it's either static or the outer class implements Serializable

    Besides that you also need to define serialVersionUID for every Serializable class. Check all 3 cases above plus:

    1. all Serializable superclasses
    2. if your class is an anonymous class, define it there too

    Note: your code may run without serialVersionUID sometimes but read the last paragraph in Serializable's javadoc to understand why it will

    be a problem depending on the environment.


    There's a VM option to add details to the exception. It will show the root and nested classes failing to serialize and help you figure out what you're missing:

    -Dsun.io.serialization.extendedDebugInfo=true
    

提交回复
热议问题