基本上,我试图在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