gpt4 book ai didi

java - Java 中应有

转载 作者:行者123 更新时间:2023-12-02 03:38:09 26 4
gpt4 key购买 nike

我正在尝试从类中的属性文件加载数据。但是我收到错误 <identifier> expected .我不明白我在这方面做错了什么,请建议我我做错了什么。

public class ToDoList {

private Properties prop = new Properties();
{
prop.load(this.getClass().getClassLoader().getResourceAsStream("file.properties"));//Here i am getting the error
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}

错误就像

<identifier> expected
illegal start of type
')' expected
';' expected
illegal start of type
<identifier> expected
';' expected
invalid method declaration; return type required
';' expected

最佳答案

您忘记了 try 关键字。应该是

try {
// statements
} catch (IOException ioe) {
// handle exception
}

并且不要忘记将代码放入方法中。

关于java - Java 中应有 <identifier>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37180194/

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