Saya memiliki pengecualian ini dan saya tidak mengerti mengapa itu akan dibuang atau, bagaimana saya harus menanganinya.
try {
os.writeObject(element);
} catch (IOException e) {
e.printStackTrace();
}
Di mana element
a yang TransformGroup
berisi beberapa TransformGroups
turunan lain dari kelas Atom:
public class Atom extends Group implements Serializable{
float pozX,pozY;
Group group= new Group();
Color3f blue = new Color3f(new Color(255));
Color3f black = new Color3f(new Color(0));
Sphere AtSph=new Sphere();
public Atom(final float WEIGHT, final int BOUNDS,final float radius,Color3f color)
{
AppSetting ap= new AppSetting(color, black);
AtSph=new Sphere(radius,1,100,ap);
}
}
Log kesalahan lengkap:
java.io.NotSerializableException: javax.media.j3d.TransformGroup
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at cls.MolecularBuilder.addAtom(MolecularBuilder.java:511)
at cls.MolecularBuilder$Console.HidrogenItemActionPerformed(MolecularBuilder.java:897)
at cls.MolecularBuilder$Console$2.actionPerformed(MolecularBuilder.java:746)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.AbstractButton.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
AppSetting
(di kelas Atom) hanyalah kelas khusus yang memperluas Penampilan.
java
exception
exception-handling
notserializableexception
Mihai Bujanca
sumber
sumber
javax.media.j3d.TransformGroup
itu sendiri tidak menerapkan SerializableAtom
keduanya memperpanjangGroup
dan memilikiGroup
anggota?Jawaban:
Bidang objek Anda pada gilirannya memiliki bidangnya, beberapa di antaranya tidak diimplementasikan
Serializable
. Dalam kasus Anda, kelas yang melanggar adalahTransformGroup
. Bagaimana cara mengatasinya?Serializable
transient
sumber
Serializable
dan menggunakanreadObject()
danwriteObject()
secara manual membuat serial data dari kelas pihak ketiga. Dalam beberapa kasus, ini mungkin pendekatan yang masuk akal. stackoverflow.com/a/12963580/1208581java.io.NotSerializableException
dapat terjadi ketika Anda membuat serial contoh kelas dalam karena:Ref: Antarmuka yang Dapat Disambung
sumber
Buat kelas dapat diserialkan dengan mengimplementasikan antarmuka
java.io.Serializable
.java.io.Serializable
- Marker Interface yang tidak memiliki metode apa pun di dalamnya.ObjectOutputStream
bahwa objek ini adalah objek yang dapat diserialkan.sumber