Serializable problem
in
Programming Questions
•
8 months ago
Hello all,
I am trying to make a (java) program that communicates with an other (java) program. After some searching i found out that doing it serializable, would be the easiest way because i don't have to worry about the format. So i found this example in my book Head First: Java. Except, the code below does work, but gives an error after a while ("NotSerializableException"). If i look at the output then it seems to include the Processing constants also, i didn't expect this.
Is there a way to get this working? Thanks.
p.s. made with Processing 1.5.1.
I am trying to make a (java) program that communicates with an other (java) program. After some searching i found out that doing it serializable, would be the easiest way because i don't have to worry about the format. So i found this example in my book Head First: Java. Except, the code below does work, but gives an error after a while ("NotSerializableException"). If i look at the output then it seems to include the Processing constants also, i didn't expect this.
Is there a way to get this working? Thanks.
p.s. made with Processing 1.5.1.
- import java.io.*;
- void setup() {
- GameChar Elf = new GameChar(50, "ranged", "bow");
- try {
- ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(sketchPath+"/data/game.txt"));
- os.writeObject(Elf);
- os.close();
- }
- catch (Exception e) {
- println(e);
- }
- exit();
- }
- void draw() {
- }
- class GameChar implements Serializable {
- int health;
- String type;
- String weapon;
- GameChar(int h, String t, String w) {
- health = h;
- type = t;
- weapon = w;
- }
- }
1