RE: java.lang.NullPointerException
When i trying to read the data from excel sheet and if that column is blank then webdriver throwing the error “java.lang.NullPointerException”.
So how to handle this error whenever column has no data?
Hi onimje,
You would have something like this to address a cell in your code.
1 2 3 4 |
<span class="typ">Cell</span><span class="pln"> targetCell </span><span class="pun">=</span><span class="pln"> tragetRow</span><span class="pun">.</span><span class="pln">getCell</span><span class="pun">(</span><span class="lit">3</span><span class="pun">); </span>check the cell for two conditions before performing any action on it. <span class="kwd">if</span> <span class="pun">(targetCell</span> <span class="pun">==</span> <span class="kwd">null</span> <span class="pun">||</span><span class="pln"> targetCell</span><span class="pun">.</span><span class="pln">getCellType</span><span class="pun">()</span> <span class="pun">==</span> <span class="typ">Cell</span><span class="pun">.</span><span class="pln">CELL_TYPE_BLANK)</span> |
if this codition comes out to be true you will get a null pointer else you can perform what ever action you want on  the cell.
Thanks
Virender