0

I was trying to make an application that would hold data of what their customer is buying. Code for the method that is creating trouble for me is here:

private void MyData(long Invoice, String Name, int num, String[] products, int[] quantity, double tax, double cost) throws FileNotFoundException, IOException
{
    FileInputStream inputStream = new FileInputStream(new File("SalesDetails.xlsx"));
    XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
    XSSFSheet worksheet = workbook.getSheetAt(0);
    Invoice =Invoice+3;
    for(int i=2; i<=27; i++)
    {
        XSSFCell cell=null; 
        cell = worksheet.getRow((int)Invoice).getCell(i);
        switch (i) { //some cases. }
    }

In this method, I am using Apache POI to write to an excel file.

The line where I put cell = worksheet.getRow((int)Invoice).getCell(i); is creating an exception which I am not getting why. Please help me find solution to this.

I know there is already a similar question, but the solution to it is not helping me remove the exception.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
J. Singh
  • 1
  • 2
  • @JonSkeet I know about that question, but I am still facing problem after fixing it as answered. – J. Singh Jul 13 '17 at 13:43
  • You don't use correctly the API. `getRow()` doesn't create a row if it doesn't exist. – davidxxx Jul 13 '17 at 13:43
  • @davidxxx So what is the correct way to create a row? – J. Singh Jul 13 '17 at 13:45
  • `createRow()`. I could do a more comprehensive answer but as it was closed I will not. – davidxxx Jul 13 '17 at 13:47
  • That question should help you become clearer about where the problem is, so that you won't create a question where a) there can be multiple things that are null within your own code; b) you explain how you've tried to diagnose it; c) you include the full stack trace. If you improve the question to show that you've really acted on the answers in that question, this question can be reopened. – Jon Skeet Jul 13 '17 at 13:53

0 Answers0