I am trying to read data from one .xlsx and put it in a different file. The error happens when the loop is running for the second time. There are no blank cells and all the 187 rows have data in them (checked and verified). There is only one column with data in it (the first column A), so i am not using the Null Checker. Here is the code that i have so far. I am not including the code for writing and closing the file as the error occurs during the second iteration of the loop.
FileInputStream fis=new FileInputStream("C:\\test\\Migration_input.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet = wb.getSheetAt(0);
int rowCount = sheet.getLastRowNum();
System.out.println(rowCount);
FileOutputStream fos=new FileOutputStream("C:\\test\\Migration.xlsx");
for (int b=0; b<rowCount;b++)
{
System.out.println(b);
//This part to read from existing file
XSSFRow rowreader=sheet.getRow(b);
XSSFCell cellreader = rowreader.getCell(0);
**String cellinput = cellreader.getStringCellValue(); //Errors out on this line on second iteration - It is not a null value and has some string data in it.
//This part to write in a different file
XSSFRow rowwriter=sheet.createRow(b+1);
XSSFCell cellwriter= rowwriter.createCell(2);
System.out.println(cellinput);
cellwriter.setCellType(cellwriter.CELL_TYPE_STRING);
cellwriter.setCellValue(cellinput);
System.out.println("done");
}
I changed the code to this but still seems to be having an error:
for (int b=0; b<rowCount;b++)
{
System.out.println(b);
//This part to read from existing file
XSSFRow rowreader=sheet.getRow(b);
XSSFCell cellreader = rowreader.getCell(0);
System.out.println(cellreader.getStringCellValue());
**cellinput[b] = cellreader.getStringCellValue(); //Errors out
System.out.println("stored in array string all the values");
}
And here is the updated output
0
Academic Cert Expected Date
FAILED: get_labels
java.lang.NullPointerException
at crm_migration.labels_on_given_object.get_labels(labels_on_given_object.java:99)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
It reads the value from the .xlsx fine but when i try to store it into an string array, that is when it throws the error now. I have separated the loop so that it only reads now and stores the value in an array, **again there are no null values in the first column A with 187 rows in it. Please assist.