title: Can't instantiate class error in JSF, caused by NullPointerException
body: <p>Here is my managed Bean class,</p>
  
  <pre><code>public class ChartBean implements Serializable {
  
      private PieChartModel pieModel;
  
      public ChartBean(){
          createPieModel(); 
      }
  
      public PieChartModel getPieModel() {  
          return pieModel;  
      }  
  
      private void createPieModel(){  
          try {
              pieModel = new PieChartModel();  
  
              String query = "SELECT b.countryname,count(b.countryname) FROM info.summery a,info.countrymcc b;";
              Connector conn = new Connector();
              Statement str = (Statement) conn.getConn().createStatement();
              ResultSet res = str.executeQuery(query);
  
  
              while(res.next()){
  
                    pieModel.set(res.getString(1), Integer.parseInt(res.getString(2)));
              }
          } catch (SQLException ex) {
              Logger.getLogger(ChartBean.class.getName()).log(Level.SEVERE, null, ex);
          }
      } 
  }
  </code></pre>
  
  <p>But the problem is when it is compiled it gives an error like this "Cant instantiate class: org.primefaces.examples.view.ChartBean". What is the reason??</p>
  
  <p>StackTrace:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException at  
  
  org.primefaces.examples.view.ChartBean.createPieModel(ChartBean.java:45) at     
  org.primefaces.examples.view.ChartBean.&lt;init&gt;(ChartBean.java:32) at     
  sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at     
  sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorI‌​    
  mpl.java:39) at     
  sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorA‌​    
  ccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at    
  java.lang.Class.newInstance0(Class.java:355) at java.lang.Class
  </code></pre>