how to solve java.lang.NoSuchFieldError: RETURN_NULL_AND_BLANK in java

how to solve java.lang.NoSuchFieldError: RETURN_NULL_AND_BLANK in java

public class SpreadsheetGenerator {
void dailyreport( Connection con) throws SQLException, IOException {
    Statement statement = con.createStatement();
    ResultSet resultSet = null;
    try {
        resultSet = statement.executeQuery("select * from ssa_msg_daily");
    } catch (Exception e) {

    } finally {
        ResultSet resultSet = statement.executeQuery("select * from ssa_msg_daily");
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet spreadsheet = workbook.createSheet("employe db");

        XSSFRow row = spreadsheet.createRow(1);
        XSSFCell cell;
        cell = row.createCell(1);
        cell.setCellValue("id");
        cell = row.createCell(2);
        cell.setCellValue("Sender");
        cell = row.createCell(3);
        cell.setCellValue("Service");
        cell = row.createCell(4);
        cell.setCellValue("Message_identifier");
        cell = row.createCell(5);
        cell.setCellValue("Date");
        cell = row.createCell(6);
        cell.setCellValue("Incoming");
        cell = row.createCell(7);
        cell.setCellValue("Outgoing");
        int i = 2;

        while (resultSet.next()) {
            row = spreadsheet.createRow(i);
            cell = row.createCell(1);
            cell.setCellValue(resultSet.getInt("id"));
            cell = row.createCell(2);
            cell.setCellValue(resultSet.getString("Sender"));
            cell = row.createCell(3);
            cell.setCellValue(resultSet.getString("Service"));
            cell = row.createCell(4);
            cell.setCellValue(resultSet.getString("Message_identifier"));
            cell = row.createCell(5);
            cell.setCellValue(resultSet.getDate("Date"));
            cell = row.createCell(6);
            cell.setCellValue(resultSet.getString("Incoming"));
            cell = row.createCell(7);
            cell.setCellValue(resultSet.getString("Outgoing"));
            i++;
        }

        FileOutputStream out = new FileOutputStream(new File("exceldatabase.xlsx"));
        workbook.write(out);
        out.close();
        System.out.println("exceldatabase.xlsx written successfully");
    }
    }


}

此处ssa_msg_daily在table中包含空值或空值,所以
编译时出现错误

线程“主”中的异常java.lang.NoSuchFieldError:RETURN_NULL_AND_BLANK

出现@XSSFWorkbook 工作簿=新的XSSFWorkbook(); 我该如何处理这种情况以及 我正在使用结果集使用 apache poi

转换为电子表格

也许你会尝试使用“try”和“catch”。

public class SpreadsheetGenerator {
void dailyreport( Connection con) throws SQLException, IOException {
Statement statement = con.createStatement();
ResultSet resultSet = null;
try {
    resultSet = statement.executeQuery("select * from ssa_msg_daily");
} catch (Exception e) {

} 
    //ResultSet resultSet = statement.executeQuery("select * from ssa_msg_daily");
    XSSFWorkbook workbook = new XSSFWorkbook();
    XSSFSheet spreadsheet = workbook.createSheet("employe db");

    XSSFRow row = spreadsheet.createRow(1);
    XSSFCell cell;
    cell = row.createCell(1);
    cell.setCellValue("id");
    cell = row.createCell(2);
    cell.setCellValue("Sender");
    cell = row.createCell(3);
    cell.setCellValue("Service");
    cell = row.createCell(4);
    cell.setCellValue("Message_identifier");
    cell = row.createCell(5);
    cell.setCellValue("Date");
    cell = row.createCell(6);
    cell.setCellValue("Incoming");
    cell = row.createCell(7);
    cell.setCellValue("Outgoing");
    int i = 2;

    if(resultSet!=null){
    while (resultSet.next()) {
        row = spreadsheet.createRow(i);
        cell = row.createCell(1);
        cell.setCellValue(resultSet.getInt("id"));
        cell = row.createCell(2);
        cell.setCellValue(resultSet.getString("Sender"));
        cell = row.createCell(3);
        cell.setCellValue(resultSet.getString("Service"));
        cell = row.createCell(4);
        cell.setCellValue(resultSet.getString("Message_identifier"));
        cell = row.createCell(5);
        cell.setCellValue(resultSet.getDate("Date"));
        cell = row.createCell(6);
        cell.setCellValue(resultSet.getString("Incoming"));
        cell = row.createCell(7);
        cell.setCellValue(resultSet.getString("Outgoing"));
        i++;
    }}

    FileOutputStream out = new FileOutputStream(new File("exceldatabase.xlsx"));
    workbook.write(out);
    out.close();
    System.out.println("exceldatabase.xlsx written successfully");
}
}
 

}

您遇到了类路径问题。您的类路径中有多个版本的 Apache POI 项目。这种版本混合导致 类 之一的较新版本试图与旧版本之一通信,但它们不兼容。

解决方案是检查您的类路径(因此,如果您使用 Maven,gradle,或其他一些依赖系统,依赖链),并修复它。可能就像 运行 在您的构建系统上执行 'clean' 命令一样简单。

注意:您的代码风格非常糟糕 - 不要在 finally 块中放置大量代码。此外,99.9% 的糊状物是红鲱鱼。 one-liner 已经会导致您的问题:

XSSFWorkbook workbook = new XSSFWorkbook();

其他的无关紧要