シリアル化のチュートリアルに従ったところ、なぜ機能しないのか疑問に思います。私はこのようなゲームクラスを持っています:
import java.io.Serializable;
public class Game implements Serializable{
private static final long serialVersionUID = -4795536311274486893L;
protected int SHOT_SPEED;
protected int PLAYER_SPEED;
Player player;
ArrayList<SpaceObject> objects;
int level, score;
Dimension resolution;
and so on...
そして、オブジェクトIOを処理する必要がある私のリーダーメソッドは次のようになります。
public boolean saveGame(Game game) {
try {
FileOutputStream fileOut = new FileOutputStream(defaultDataName+".ser");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(game);
out.close();
fileOut.close();
return true;
}
catch (IOException i) {
return false;
}
}
public Game loadGame() throws IOException {
if (readRawData(defaultDataName) == "") throw new IOException("Data was deleted");
Game game = null;
try {
FileInputStream fileIn = new FileInputStream(defaultDataName+".ser");
ObjectInputStream in = new ObjectInputStream(fileIn);
game = (Game) in.readObject();
in.close();
fileIn.close();
}
catch (ClassNotFoundException e) {
throw new IOException("Class not Found: " + e.getMessage());
}
return game;
}
私の考えでは、チュートリアルとまったく同じようにすべてを行ったので、なぜうまくいかないのですか。(ClassNotFoundErrorがスローされます。ご協力いただきありがとうございます。