I am working on a little quiz tool and face problems when I want to persist my objects (questions). This is my save method within the class Question, which imports "java.io.*":
public static boolean saveQuestion(String file, Question q){
try{
FileOutputStream saveFile=new FileOutputStream(file);
ObjectOutputStream save = new ObjectOutputStream(saveFile);
save.writeObject(q);
save.close();
return true;
}
catch(Exception exc){
exc.printStackTrace();
return false;
}
}
This is how I call the method from another class:
Question q = new Question();
Question.saveQuestion("question.sav",q);
When I try to run it, it throws a "java.io.NotSerializableException" at the save.writeObject(q);
When I change my code in order to just store an attribute of the object it works fine. What can be the problem?