Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更改apachee POI中的getROW索引引发NullPointerException_Java_Selenium Webdriver_Apache Poi - Fatal编程技术网

Java 更改apachee POI中的getROW索引引发NullPointerException

Java 更改apachee POI中的getROW索引引发NullPointerException,java,selenium-webdriver,apache-poi,Java,Selenium Webdriver,Apache Poi,我正在尝试使用apachee POI编写Excel。当getrow索引为0时,它会像[getrow(o)]一样工作。但更改它而不是零会引发空指针异常 package fairfoxchecking; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.xssf.usermode

我正在尝试使用apachee POI编写Excel。当getrow索引为0时,它会像[getrow(o)]一样工作。但更改它而不是零会引发空指针异常

package fairfoxchecking;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class writingInExcel {
    public static void main(String []args) throws IOException {

    File src = new File("D:/Etl_Bug_reporting_Template.xlsx");
    FileInputStream fis = new FileInputStream(src);
    XSSFWorkbook wb = new XSSFWorkbook(fis);
    XSSFSheet sheet1 =wb.getSheetAt(0);

    sheet1.getRow(0).createCell(5).setCellValue("cheasdfasdfasck1");
    sheet1.getRow(1).createCell(5).setCellValue("cheasdfasdfasck1");

    FileOutputStream fout = new FileOutputStream(src);
    wb.write(fout);
    wb.close();
}
根据,如果未定义getRow,则它可能返回null。因此,您可能必须在编写之前创建一个

sheet1.createRow(索引)


检查此项-似乎很好。

根据,如果未定义,getRow可能返回null。因此,您可能必须在编写之前创建一个

sheet1.createRow(索引)



选中此选项-看起来不错。

在创建单元格之前,必须确保已创建行

试一试

if(sheet1.getRow(rowIndex) == null)
      sheeet1.createRow(rowIndex)
sheet1.getRow(rowIndex).createCell(colIndex).setCellValue(stringVal);

在创建单元格之前,必须确保已创建行

试一试

if(sheet1.getRow(rowIndex) == null)
      sheeet1.createRow(rowIndex)
sheet1.getRow(rowIndex).createCell(colIndex).setCellValue(stringVal);

请确保仅当该索引中当前没有行时调用createRow(),否则将用新创建的行覆盖现有行。请确保仅当该索引中当前没有行时调用createRow(),否则将用新创建的行覆盖现有行。