I'm trying to write a lo list, which is my ArrayList files with various objects:
ArrayList & lt; Person & gt; PersonList = New Arrestists & lt; Person & gt; (); private individual; Captain; init () {// null list personList.add (new coach ( "Tesan De Boer", "Vieruslaan 3 B", "+068 9 337 554")) to the people being added; PersonList.add (new goalkeeper ("Peter Post", "Eviewview Student 66", "2222", 1)); PersonList.add (new goalkeeper ("Piet Puck", "Velocity van Onganade 88", "2222", 21)); PersonList.add (new goalkeeper ("SIM van Anhulat", "Straightway 45", "0612213446", 31)); PersonList.add (new fielder ("coan vjenk", "straightway 45", "2222", 2)); PersonList.add (new fielder ("Jan-William Rufus op Den Har", "Straightway 45", "0614226698", 3)); PersonList.add (new fielder ("Tom Kronicker", "Straightway 45", "06 9 83663", 4)); PersonList.add (new fielder ("Leon Het Kanon", "Straightway 45", "2222", 6)); PersonList.add (new fielder ("Robin Hajjent", "Straightway 45", "2222", 7)); PersonList.add (new fielder ("Leo do Cat", "Straightway 45", "222", 8)); PersonList.add (new fielder ("Morris D Spey", "Straightway 45", "2222", 9)); PersonList.add (new fielder ("Rein Zoker", "Straightway 45", "2222", 10)); PersonList.add (new fielder ("Daryan Pock", "Straightway 45", "2222", 11)); PersonList.add (new fielder ("Akadem de Baum", "Straightway 45", "2222", 12)); } And here I am trying to write that ArrayList to test a file called:
public class Main {public static void I (String [] Args throws exceptions {Team Team = New Team (); Team.init (); ArrayList & LT; Person & gt; PlayerData = Team.GetServerlist (); Try {// Create a new file with an object overputstream fileoptput stream = new file optup stream ("test.txt"); ObjectOutputStream OUT = New ObjectOutputStream (outside); // Write something in the file oout.writeObject (playersData); // close the stream oout.close (); // We create an ObjectInputStream for the file created before ObjectInputStream OIS = New ObjectInputStream (New FileInputStream ("test.txt")); } Hold (Exception pre) {ex.printStackTrace (); }} }
When I run the program I get this error:
java.io.NotSerializableException: Coach in Java java.io.ObjectOutputStream.writeObject (unknown source sun.reflect.NativeMethodAccessorImpl.invoke0 (Native method) at .io.ObjectOutputStream.writeObject0 (unknown source) java.util.ArrayList.writeObject (unknown source) at sun.reflect) on KNativeMethodAccessorImplkinvoke (unknown source) SunkreflectkDelegatingMethodAccessorImplkinvoke (unknown source java.lang.reflect.Method.invoke on java.io.ObjectStreamClass.invokeWriteObject on Javakio) (unknown source) (unknown source) .ObjectOutputStream.writeSerialData (unknown sources ) On java.io.ObjectOutputStream.writeOrdinaryObject (Unknown Source) at java.io.ObjectOutputStream.writeObject0 (Unknown Source) at java.io.ObjectOutputStream.writeObject (Unknown Source) at Main.main (primarily .java: 24) I thought ArrayList was serializable, so I do not know why a demographic exception has been thrown out. I hope you see why this exception has been thrown away.
Thank you in advance!
Since your ArrayList with Coach For example, if you just coach class to implement JavakiokSerializable (and probably you Goalkeeper or Kshetrr ) as the other classes.
When Trewarsing a graph, may face an object that does not support Siriyljabl interface. In this case, the neurorizable option will be thrown away and will identify the category of non-cerebrisable objects.
However, for full details rather than the work of serialization in Java is complex, View
No comments:
Post a Comment