loading data to hashmap<String, HashMap<String, HashMap<String,ArrayList<ClassOb>>>>
<p>I am trying to load data to hash map of hash map and i keep getting null pointer and not sure if i am doing the right thing.</p>

<p>I want my hash map to be based on three keys SalesAreaCode, year and product. I want to store the rest in arraylist. I want to pass sales area code , year and product and list all product such as customer, quantity , price related to these three keys:
I really need help or someone to point me to the right direction. Any help will be appreciated!! Alan</p>

<p>Code:</p>

<pre><code> public HashMap&lt;String, HashMap&lt;String, HashMap&lt;String, ArrayList&lt;Sales&gt;&gt;&gt;&gt; getSalesDetails(Connection con)
{
        HashMap&lt;String, HashMap&lt;String, HashMap&lt;String, ArrayList&lt;Sales&gt;&gt;&gt;&gt;&gt; hmpSales =
        new  HashMap&lt;String, HashMap&lt;String, HashMap&lt;String, ArrayList&lt;Sales&gt;&gt;&gt;&gt;&gt;();
        Sales s;
        HashMap&lt;String,ArrayList&lt;Sales&gt;&gt; hmpSalProd = new HashMap&lt;String, ArrayList&lt;Sales&gt;&gt;();
        HashMap&lt;String,HashMap&lt;String,ArrayList&lt;Sales&gt;&gt;&gt; hmpSalYear = 
        new HashMap&lt;String, ArrayList&lt;Sales&gt;&gt;&gt;();    

       try
       {
             pst = con.prepareStatement(sql);
       rs=pst.executeQuery();
       while(rs.next())
       {
                  s=new Sales();

                  if(!(hmpSalProd.containskey(rs.getString("product"))))
                  {
                       s.setSalesCode(rs.getString("sacd"));
                       s.setCustomerCode(rs.getString("custcd"));
                       s.setYear(rs.getInt("year"));
                       s.setProduct(rs.getString("product"));
                       s.setPrice(rs.getDouble("price"));
                       s.setQty(rs.getInt("qty"));
                       hmpSalProd.put(rs.getString("product"),
                       new ArrayList&lt;Sales&gt;(Arrays.asList(s)));
                  }
                  else
                  {
                      s.setSalesCode(rs.getString("sacd"));
                      s.setCustomerCode(rs.getString("custcd"));
                      s.setYear(rs.getInt("year"));
                      s.setProduct(rs.getString("product"));
                      s.setPrice(rs.getDouble("price"));
                      s.setQty(rs.getInt("qty"));
                      hmpSalProd.get(rs.getString("product")).add(s);
                  }
                  if(!(hmpSalYear.containsKey(String.valueOf(rs.getInt("year")))))
                  {
                      hmpSalYear.put(String.valueOf(rs.getInt("year")),hmpSalProd);
                  }
                  else
                  {
                      hmpSalYear.get(String.valueOf(rs.getInt("year"))).
                      get(rs.getString("product")).add(s);
                  }

                  if(!(hmpSalArea.containsKey(rs.getString("sacd"))))
                  {
                     hmpSales.put(rs.getString("sacd"),hmpSalYear);
                  }
                  else
                  {
                      hmpSales.get(rs.getString("sacd")).
                      get(String.valueOf(rs.getInt("year"))).
                      get(rs.getString("product")).add(s);
                  }

          }
          pst.close();
          rs.close();
     }
     catch(SQLException se)
     {
           System.out.println("error loading: " + se.getMessage());
     }
     return hmpSales;

}          
</code></pre>
