Android ゲーム (Windows ラップトップの Android シミュレーターでプレイ) を保存しようとすると、FileNotFoundException
. さまざまなことを試すのに何時間も費やしましたが、Android 用ではない以前のバージョンでコードが完全に機能するため、当惑したままです。
FileOutputStream saveStream;
ObjectOutputStream savePlayerObject = null;
String destinationFile = player1.getName() + ".txt";
try
{
saveStream = new FileOutputStream(destinationFile);
savePlayerObject = new ObjectOutputStream(saveStream);
savePlayerObject.writeObject(player1);
}
catch(FileNotFoundException ex)
{
Toast toast = Toast.makeText(getApplicationContext(), "Save Failed", Toast.LENGTH_LONG);
toast.show();
}
catch(IOException ex)
{
Toast toast = Toast.makeText(getApplicationContext(), "Save Failed", Toast.LENGTH_LONG);
toast.show();
}
finally
{
try
{
if(savePlayerObject !=null)
{
savePlayerObject.flush();
savePlayerObject.close();
Toast toast = Toast.makeText(getApplicationContext(), "Thank-You For Playing, See You Soon", Toast.LENGTH_LONG);
toast.show();
System.exit(0);
}
}
catch(IOException ex)
{
Toast toast = Toast.makeText(getApplicationContext(), "Save Failed", Toast.LENGTH_LONG);
toast.show();
}
}