我有一个名为Libro的类,它只包含字符串:
public class Libro {
private String titolo;
private String autore;
private String editore;
private String sottotitolo;
private String genere;
private String dpubb;
private String lpubb;
private String soggetto;
private String isbn;
private String note;
private String prezzo;
private String npag;
//getters, setters, constructors...
}
然后我创建了一个名为a
的对象,属于Libro
类,我尝试将其写入coso.dat
文件
try{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("C:\\Users\\Workbench\\Documents\\NetBeansProjects\\coso.dat"));
out.writeObject(a);
out.close();
}catch(Exception e) {System.out.println("Damn");}
然后我用NotePad打开文件,似乎我试图序列化一个不可序列化的类:
¬í {sr java.io.NotSerializableException(Vx ç†5 xr java.io.ObjectStreamExceptiondÃäk9ûß xr java.io.IOExceptionl€sde%ð« xr java.lang.ExceptionÐý>;Ä xr java.lang.ThrowableÕÆ5'9w¸Ë L causet Ljava/lang/Throwable;L
detailMessaget Ljava/lang/String;[
stackTracet [Ljava/lang/StackTraceElement;L suppressedExceptionst Ljava/util/List;xpq ~ t ginobook.classi.Librour [Ljava.lang.StackTraceElement;F*<<ý"9 xp )sr java.lang.StackTraceElementa Åš&6Ý… I
lineNumberL declaringClassq ~ L fileNameq ~ L
methodNameq ~ xp t java.io.ObjectOutputStreamt ObjectOutputStream.javat writeObject0sq ~
\q ~ q ~ t writeObjectsq ~
ôt ginobook.forms.FormNuovot FormNuovo.javat btnCreaActionPerformedsq ~
q ~ q ~ t access$1500sq ~
Œt ginobook.forms.FormNuovo$15q ~ t actionPerformedsq ~
æt javax.swing.AbstractButtont AbstractButton.javat fireActionPerformedsq ~
,t "javax.swing.AbstractButton$Handlerq ~ q ~ sq ~
’t javax.swing.DefaultButtonModelt DefaultButtonModel.javaq ~ sq ~
q ~ $q ~ %t
setPressedsq ~
üt *javax.swing.plaf.basic.BasicButtonListenert BasicButtonListener.javat
mouseReleasedsq ~
…t java.awt.Componentt Component.javat processMouseEventsq ~
üt javax.swing.JComponentt JComponent.javaq ~ /sq ~
šq ~ -q ~ .t processEventsq ~
¼t java.awt.Containert Container.javaq ~ 4sq ~
q ~ -q ~ .t dispatchEventImplsq ~
öq ~ 6q ~ 7q ~ 9sq ~
gq ~ -q ~ .t
dispatchEventsq ~
t java.awt.LightweightDispatcherq ~ 7t retargetMouseEventsq ~
q ~ >q ~ 7q ~ /sq ~
rq ~ >q ~ 7q ~ <sq ~
èq ~ 6q ~ 7q ~ 9sq ~
ºt java.awt.Windowt Window.javaq ~ 9sq ~
gq ~ -q ~ .q ~ <sq ~
öt java.awt.EventQueuet EventQueue.javaq ~ 9sq ~
aq ~ Hq ~ It
access$500sq ~
Åt java.awt.EventQueue$3q ~ It runsq ~
¿q ~ Mq ~ Iq ~ Nsq ~
ÿÿÿþt java.security.AccessControllert AccessController.javat doPrivilegedsq ~
Lt 5java.security.ProtectionDomain$JavaSecurityAccessImplt ProtectionDomain.javat doIntersectionPrivilegesq ~
Vq ~ Uq ~ Vq ~ Wsq ~
Ût java.awt.EventQueue$4q ~ Iq ~ Nsq ~
Ùq ~ Zq ~ Iq ~ Nsq ~
ÿÿÿþq ~ Qq ~ Rq ~ Ssq ~
Lq ~ Uq ~ Vq ~ Wsq ~
Øq ~ Hq ~ Iq ~ <sq ~
Ét java.awt.EventDispatchThreadt EventDispatchThread.javat pumpOneEventForFilterssq ~
tq ~ `q ~ at pumpEventsForFiltersq ~
iq ~ `q ~ at pumpEventsForHierarchysq ~
eq ~ `q ~ at
pumpEventssq ~
]q ~ `q ~ aq ~ hsq ~
Rq ~ `q ~ aq ~ Nsr &java.util.Collections$UnmodifiableListü%1µìŽ L listq ~ xr ,java.util.Collections$UnmodifiableCollectionB €Ë^÷ L ct Ljava/util/Collection;xpsr java.util.ArrayListxÒ™Ça I sizexp w xq ~ px
我做错了什么..?如果这个问题看似愚蠢,我很抱歉,但我找不到任何答案