gpt4 book ai didi

java - 获取 java.io.WriteAbortedException : writing aborted; java. io.NotSerializableException,即使我实现可序列化

转载 作者:行者123 更新时间:2023-11-29 08:52:23 25 4
gpt4 key购买 nike

<分区>

public static void addToFile(LinkedList<Carowners> carowner)
{
try
{
File file = new File(filename);
FileOutputStream fout= new FileOutputStream(file);
ObjectOutputStream out= new ObjectOutputStream(fout);
out.writeObject(carowner);
out.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}

嗨,这是我的代码。我在对象序列化时遇到以下错误。我为类实现了可序列化。

java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: 

Billing.Person
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at java.util.LinkedList.readObject(LinkedList.java:1136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:1004)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1872)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1777)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at Billing.Carownerslist.<init>(Carownerslist.java:42)
at Billing.Carownerslist.main(Carownerslist.java:253)
Caused by: java.io.NotSerializableException: Billing.Person
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at java.util.LinkedList.writeObject(LinkedList.java:1118)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:975)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1480)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
at Billing.Carownerslist.addToFile(Carownerslist.java:242)
at Billing.Carownerslist.addCompany(Carownerslist.java:160)
at Billing.Carownerslist.main(Carownerslist.java:285)
Exception in thread "main" java.lang.NullPointerException
at Billing.Carownerslist.addCompany(Carownerslist.java:149)
at Billing.Carownerslist.main(Carownerslist.java:278)
Java Result: 1

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com