当我将 ExcelDataConfig 方法声明为静态时,它会写入错误:java: modifier static not allowed here。可能是什么原因 ?谢谢 !
public class ExcelDataConfig {
static XSSFWorkbook wb;
static XSSFSheet sheet;
static String excelPath = "C:\\UsersData.xlsx";
public static ExcelDataConfig() {
try {
File src = new File(excelPath);
FileInputStream fs = new FileInputStream(src);
wb = new XSSFWorkbook(fs);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public static String getData(int row, int column) {
sheet = wb.getSheetAt(0);
String data = sheet.getRow(row).getCell(column).getStringCellValue();
return data;
}
}
问题是方法名和类名一样
ExcelDataConfig,这是典型的类构造函数,构造函数不能static。