基本上,我試圖在Robocode中生成一個日誌文件,但我遇到了問題,因爲您無法在Robocode中使用try/catch(據我所知)。我也做了以下內容:在Robocode(Java)中編寫文件
public void onBattleEnded(BattleEndedEvent e) throws IOException
{
writeToLog();
throw new IOException();
}
和
public void writeToLog() throws IOException
{
//Create a new RobocodeFileWriter.
RobocodeFileWriter fileWriter = new RobocodeFileWriter("./logs/test.txt");
for (String line : outputLog)
{
fileWriter.write(line);
fileWriter.write(System.getProperty("line.seperator"));
}
throw new IOException();
}
,並正在逐漸編譯時出現以下錯誤: -
MyRobot.java:123: onBattleEnded(robocode.BattleEndedEvent) in ma001jh.MyRobot cannot implement onBattleEnded(robocode.BattleEndedEvent) in robocode.robotinterfaces.IBasicEvents2; overridden method does not throw java.io.IOException
public void onBattleEnded(BattleEndedEvent e) throws IOException
^
1 error
我也想看看界面。你是否只導入了'java.io.IOException'而不是別的? – adarshr 2011-03-05 14:15:58
是的,我只輸入那個。 – 2011-03-05 14:21:20