title: null pointer exception can't be fixed
body: <p>I'm implementing a software for a stock management system in java.I'm using MVC design pattern and i found this exception when trying to fill a JcomboBox. I want to get all the batches when a item-code is being passed into the method.so the method should return a array-list of relevant objects. but when I run this program it gave me this kinda error and it says there is empty result set. but i also tried the sql code manually in the terminal and it worked. so i can't imagine how to fix this error. i'm glad if anyone can tell me where is the problem. I tried to post my screen shots but it cannot be done as i don't have enough reputation </p>
  
  <p>here is my code</p>
  
  <pre><code>  String sql = "select batchNo from MainBatch where itemCode = ?";
      Connection c=DBConnection.getInstance().getConnection();
      PreparedStatement ps=c.prepareStatement(sql);
      ps.setString(1, itemCode);
      System.out.println(itemCode+" -----&gt; item code is thiss");
      ResultSet set=ps.executeQuery();
      ArrayList&lt;MainBatch&gt; list=new ArrayList&lt;&gt;();
  
      System.out.println(set.next()+" &lt;-----result set is");
      while (set.next()) {
          MainBatch batch=new MainBatch(set.getString("batchNo"));
          list.add(batch);
      }
      return list;
  </code></pre>
  
  <p>[</p>