Java NullPointerException,但仍显示正确的数据

Java NullPointerException,但仍显示正确的数据,java,excel,apache-poi,Java,Excel,Apache Poi,以下代码似乎有问题: public void write(Solution[] solutions) { writeColumnHead(); for (Solution solution : solutions) { System.out.println(solution.getDescription()); System.out.println(solution.getInstruction()); System.ou

以下代码似乎有问题:

public void write(Solution[] solutions)
{
    writeColumnHead();
    for (Solution solution : solutions) 
    {
        System.out.println(solution.getDescription());
        System.out.println(solution.getInstruction());
        System.out.println(solution.getNom());
        System.out.println(solution.getTitre());
        System.out.println(" ");
        Row row = sheet.createRow(rowNum++);
        Cell cell = row.createCell((short) 0);
        cell.setCellValue(solution.getInstruction());
        //and so on and so forth

当我第一次调用solution.something时,我在线程“main”
java.lang.NullPointerException
“中得到了一个异常,在本例中,当我调用System.out时,输出显示了正确的数据。我试图删除它们,但当我试图设置单元格值时,问题就出现了。这段代码是使用POI在Excel文件中编写的,虽然我在网上提供了许多示例,但它仍然没有编写。

stacktrace指向的行号是什么?您的
解决方案
数组可能包含空值,它是如何生成的?1)要更快获得更好的帮助,请发布一个。2) 始终复制/粘贴错误和异常输出。我从您对问题的描述中推断出两件事:1:数组中至少有一个
解决方案
s为
null
;2:
null
解决方案已接近尾声,因为您的“这些输出确实显示了正确的数据”。对调试执行此操作:在方法的顶部,
System.out.println(Arrays.toString(solutions))
然后读取控制台输出并确认哪个解决方案为空。为了在Excel工作表中写入,您需要执行workbook.write操作。你表演过吗?。另外,如果您共享异常输出和发生异常的方法代码也会更好。这确实是因为我的数组太大了,尽管我确信我正在使它精确地达到所需的大小。现在,我只需使数组略大于最大可能的条目数,然后将数据传输到一个新数组中,该数组的大小与我拥有的数据量相当。