无论如何,所以我试图制作类似聊天程序的东西,有人告诉我使用此代码检查新消息,同时允许用户提交消息:
timer.schedule(new TimerTask() {
@Override
public void run() {
read.readChat(line);
}
}, 0, 1000);
//Wait for user input
while(true) {
String bar = scan.next();
}
其中read.readChat(line);
是显示来自另一个文件的消息的方法。Java告诉我,read
两者line
都必须声明为final
......我不明白为什么特别是对于“ line
”,因为那是一个变量,我需要它来改变。
此外,在我将它们声明为 final 之后,我得到了这个错误:
unreported exception java.lang.Exception; must be caught or declared to be thrown
read.readChat(salt);
我究竟做错了什么?