Java try/catch 类构建参数的错误
我对编码还很陌生,正在开发一个项目,其想法是查看 Excel 电子表格,然后创建一个类,为每行信息构建一个语句。我下面有以下代码。
public class Message {
// information from excel
String excelPath = "./data/RecruiterData.xlsx";
String sheetName = "Sheet1";
ExcelUtils excel = new ExcelUtils(excelPath, sheetName);
int excelRowCount = excel.getRowCount();
// build recruiter class
public static Recruiter[] buildRecruiter = {
try {
// this needs to be a for each cell filled in excel, create an instance of recruiter
for (int i = 0; i < excelRowCount; i++) {
new Recruiter(excel.getCellData(1, i), excel.getCellData(2, i), excel.getCellData(3, i), excel.getCellData(4, i));
}
} catch (Exception e) {
System.out.println("Something went wrong");
}
}
但它却给了我一堆错误。第一个错误出现在 public static Recruiter[] 中,在该行的末尾,它显示:期望 } 期望。
接下来,我的 try catch 语句有错误,只是说意外的标记。
最后,它为新 Recruiter 行中的每个参数提供一个错误,指出未处理的异常:java.io.IOException。我在网上寻求帮助没有成功,所以我想我会询问一下。太感谢了!
I am still pretty new to coding and am working on a project where the idea is to look over an excel spreadsheet and put then create a class that builds a statement for each row's information. I have the following code below.
public class Message {
// information from excel
String excelPath = "./data/RecruiterData.xlsx";
String sheetName = "Sheet1";
ExcelUtils excel = new ExcelUtils(excelPath, sheetName);
int excelRowCount = excel.getRowCount();
// build recruiter class
public static Recruiter[] buildRecruiter = {
try {
// this needs to be a for each cell filled in excel, create an instance of recruiter
for (int i = 0; i < excelRowCount; i++) {
new Recruiter(excel.getCellData(1, i), excel.getCellData(2, i), excel.getCellData(3, i), excel.getCellData(4, i));
}
} catch (Exception e) {
System.out.println("Something went wrong");
}
}
But yet it is giving me a bunch of errors. The first error is in the public static Recruiter[] where right at the end of that line, it says ; expect } expected.
Next, there are errors with my try catch statement just saying unexpected token.
Finally, it is giving each parameter in the new Recruiter line an error saying unhandled exception: java.io.IOException. I was not sucessful trying to find help online so I thought I would ask about it. Thank you so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,我认为你的错误是在方法声明中
mmmm i think your error is in the method declaration