gpt4 book ai didi

java - 此行有多个标记 - 标记 ")"上的语法错误,;预期 - token "("上的语法错误,{预期

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:25 28 4
gpt4 key购买 nike

我正在学习 Java(对不起,我的英语很差,这不是我的母语),当我在 Eclipse (JavaSE-1.7) 中在我输入的每个“try”中执行“try-finally” block 时,会出现以下消息:

Multiple markers at this line - Syntax error, insert "}" to complete Block - Syntax error, insert "Finally" to complete BlockStatements

完整代码如下:

package Java;

public class Arquivo3 {

private Path BdC = Paths.get("C:/xti/files/conta.txt");
private Charset utf8 = StandardCharsets.UTF_8;

public void armazenarContas(ArrayList<Conta> contas) throws IOException{
try(BufferedWriter writer = Files.newBufferedWriter(BdC, utf8)) {
for (Conta conta : contas) {
writer.write(conta.getCliente() + ";" + conta.getSaldo() + "\n");
}
}
}

public ArrayList<Conta> recuperarContas() throws IOException{
ArrayList<Conta> contas = new ArrayList<Conta>();
try (BufferedReader reader = Files.newBufferedReader(BdC, utf8)){
String line = null;
while((line = reader.readLine()) != null) {
String[] t = line.split(";");
Conta conta = new Conta(t[0], Double.parseDouble(t[1]));
contas.add(conta);
}
}finally {
return contas;
}

}

public static void main(String[] args) throws IOException{
/*
ArrayList<Conta> contas = new ArrayList<Conta>();
contas.add(new Conta("Ricardo", 12000.23));
contas.add(new Conta("Lawrence", 11050.32));
contas.add(new Conta("Sandra", 18000.21));
contas.add(new Conta("Beatriz", 23200.09));
*/
Arquivo3 operacao = new Arquivo3();
//operacao.armazenarContas(contas);
ArrayList<Conta> contas2 = operacao.recuperarContas();
for (Conta conta : contas2) {
conta.exibeSaldo();
}
}

}

最佳答案

使用OP的评论

@yan Odd, I use jdk7 and this works for me, but then, maybe eclipse uses jdk6 for testing for syntax errors. – gangqinlaohu 2 hours ago

这是正确的。您正在使用一些 jdk7 功能,但 eclipse 配置为使用 jdk6(或更早版本)。以下是使用 eclipse 启用 jdk7 的说明(changing eclipse's java compiler to jdk7)。

具体来说,合规性设置。

关于java - 此行有多个标记 - 标记 ")"上的语法错误,;预期 - token "("上的语法错误,{预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16137302/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com