N
Netlopa
Hello,
I'm creating a project (a game) for the university ... but I am in trouble with the management of files (for now, the save).
I still have this exception "java.io.NotSerializableException".
I tried to put anything as a parameter ... but nothing.
To give you an example: the class crossfire.Orco contains various attributes and methods inside ... I would not want this to be the problem and then that should put the "primitive types" (like int, String, etc ...) separated.
Do you have an idea?
Thanks in advance
Netlopa
--
Here I post the code I used for save the file
public class File {
/**
* Create a simple Hashtable and serialize it to a file called
* HTExample.ser.
*/
public static void doSave(Object gestore) {
System.out.println();
System.out.println("+------------------------------+");
System.out.println("| doSave Method |");
System.out.println("+------------------------------+");
System.out.println();
Hashtable h = new Hashtable();
h.put("gestore.Partita", gestore);
/*h.put("string", "Oracle / Java Programming");
h.put("int", new Integer(36));
h.put("double", new Double(Math.PI));*/
try {
System.out.println("Creating File/Object output stream...");
FileOutputStream fileOut = new FileOutputStream("D:\\HTExample.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
System.out.println("Writing Hashtable Object...");
out.writeObject(h);
System.out.println("Closing all output streams...\n");
out.close();
fileOut.close();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
I'm creating a project (a game) for the university ... but I am in trouble with the management of files (for now, the save).
I still have this exception "java.io.NotSerializableException".
I tried to put anything as a parameter ... but nothing.
To give you an example: the class crossfire.Orco contains various attributes and methods inside ... I would not want this to be the problem and then that should put the "primitive types" (like int, String, etc ...) separated.
Do you have an idea?
Thanks in advance
Netlopa
--
Here I post the code I used for save the file
public class File {
/**
* Create a simple Hashtable and serialize it to a file called
* HTExample.ser.
*/
public static void doSave(Object gestore) {
System.out.println();
System.out.println("+------------------------------+");
System.out.println("| doSave Method |");
System.out.println("+------------------------------+");
System.out.println();
Hashtable h = new Hashtable();
h.put("gestore.Partita", gestore);
/*h.put("string", "Oracle / Java Programming");
h.put("int", new Integer(36));
h.put("double", new Double(Math.PI));*/
try {
System.out.println("Creating File/Object output stream...");
FileOutputStream fileOut = new FileOutputStream("D:\\HTExample.ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
System.out.println("Writing Hashtable Object...");
out.writeObject(h);
System.out.println("Closing all output streams...\n");
out.close();
fileOut.close();
} catch(FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}