title: How to handle null pointer exception using hibernate native sql query?
body: <p>I have a select query on five columns,one of which may or may not contain a value and as hibernate's native sql query always returns an object which is then required to convert using toString(),null pointer exception is encountered. How can i avoid this situation? </p>
  
  <p>Here are the code snippets,</p>
  
  <pre><code>   sql="SELECT * FROM (SELECT t.*,ROWNUM r FROM("+sqlQuery+") t)  WHERE r  BETWEEN " + intStartIndex + " AND " + intEndIndex;
      Query query=session.createSQLQuery(sql);  
      ArrayList&lt;Object[]&gt; listResult= query.list();
      return listResult;
  
  
   for(int j=0;j&lt;arrColumnMetaData.size();j++){  //  where arrColumnMetaData stores the list returned 
     int k-0;
               Object obj[]=(Object[])arrColumnMetaData.get(j);
                childBeanObj.setNumCaptureCode(obj[k++].toString());
                childBeanObj.setTxtFileName(obj[k++].toString());
                childBeanObj.setTxtFileStatus(obj[k++].toString());
                childBeanObj.setTxtDocumentCode(obj[k++].toString()); 
  }
  </code></pre>
  
  <p>i am doing something like this.. kindly tell if this is  the right approach or suggest if u have a better one.</p>