Serializing problems. Help appreciated.
I am modelling the universe for a Java game. I have it working with JBDC and
Access tables but I want to make it far more simple (and make it harder for
people to hack the tables and cheat)
I decided to use serialization to hande the Unvirse Object but all I get is
a 38 byte file.
The SaveGame class eventually will handle all the loading and saving of the
game using serialization.
Can anybody tell me where I am going wrong? I have checked and the Universe
object is full of data but it does not serialize to a file.
Many thanks
Andy
Further details below:-
The Universe object comprises an arraylist of Galaxy objects.
Galaxy comprises a String name and an arraylist of SolarSystem objects
SolarSystem Objects comprise a String name and an arraylist of
PlanetaryBodies objects
PlanetaryBodies objects comprise a collection of primitives, Strings etc
All objects have been declared similar to "public class Galaxy implements
Serializable{"
The SaveGame Class is below:-
import java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class SaveGame{
public SaveGame(){
String filename="SaveGame1.gam";
Universe uni;
FileOutputStream fos = null;
ObjectOutputStream out = null;
try
{
uni=new Universe();
fos = new FileOutputStream(filename);
out = new ObjectOutputStream(fos);
out.writeObject(uni);
out.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
}