Read Excel file containing multiple values in single column -Java
<p>I'm reading Excel file using Apache POI.
My Excel table structure is like this</p>

<pre><code>|2000s| 2001, 2003, 2008, 2009|
</code></pre>

<p>so for right hand side data, I require it to assign to 2000s</p>

<p>Till now I've implemented this way:</p>

<pre><code>List&lt;Class&gt; list = new ArrayList&lt;Class&gt;();
        File file = new File(file_path);
        FileInputStream fis = new FileInputStream(file);

        //Create an instance of workbook which refers to an excel file
        XSSFWorkbook wb = new XSSFWorkbook(fis);

        //This selects the 1st sheet 
        XSSFSheet sheet =  wb.getSheetAt(0);

        //Iterate through each row one by one
        Iterator&lt;Row&gt; itr = sheet.iterator();
        String newName = null; 
        String oldName = null;


        while(itr.hasNext()){
            Row nextRow = itr.next();
            // For each row, iterate through all the columns
            Iterator&lt;Cell&gt; cellIterator = nextRow.cellIterator();
            while (cellIterator.hasNext()) 
            {
                Cell cell = cellIterator.next();

                newName =  nextRow.getCell(0).toString();

                if(nextRow.getCell(1).toString().contains(",")){
                    StringTokenizer st = new StringTokenizer(nextRow.getCell(1).toString(),",");
                    while(st.hasMoreTokens()){
                        oldName = st.nextToken();
                    }
                }
                else{
                     oldName = nextRow.getCell(1).toString();
                }
            }

            System.out.println();
        }   
</code></pre>

<p>When I compile, it throws me "Null pointer Exception" at <code>nextRow.getCell(1)</code> line.</p>

<p>I don't understand how do I map all comma values to  2000s.</p>

<p>This is working perfectly fine for normal data(without comma).</p>