MyClass NotSerializableException

我创建了一个名为Components. 它有一些组件,如Button, TextArea,VerticalLayout等。我没有使这个类可序列化,因为我不需要,但是当我启动服务器时(我使用 Tomcat),我得到这个错误:


java.io.NotSerializableException: com.vaadin13.Components

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)

    at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)

    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

    at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1378)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)

    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)

    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)

    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)

    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)

    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)

...

当我的类不可序列化时,为什么会出现此错误,我该如何解决?


潇潇雨雨
浏览 94回答 1
1回答

月关宝盒

要修复此错误,请实现 Serializable 接口并为其指定一个 id。 Public class Foo implements Serializable {     private static final long serialversionUID = 1L; // example      //code then }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java