Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

NullPointer Exception while using Apache POI

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if(cell8[j].getCellType()==Cell.CELL_TYPE_BLANK) throws a NullPointerException. Dont know why...
Please help.....

 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are creating an array with 8 elements in it, but you are not actually putting anything into the array, so you currently have 8 null array elements.

missed the lines ahead where you fill the array in.

but you are still getting a null pointer exception because there is nothing in the element.
 
Marshal
Posts: 65806
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And fabs[j] = new String(); should be deleted. It does nothing. You might do well to get rid of the assignment to null in line 13; that is another problem waiting to happen later on.
 
Paras Ahuja
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you see this is these rows are 8th in list in the template i'm reading. I have same code for row1,row2,......,row7 before this one. But when i try to upload data from this excel sheet into my GUI, the error occurs at row8 (as i specified before). I am filling only row1 cells to be read and leaving all the remaining cells blank.
Why the error is not generated for row2,row3,.....row7?
 
Wendy L Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could you post a sceen shot, as I am not following that link, sorry
 
Sheriff
Posts: 21804
104
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
row8[j].getCell(3) will return null if the cell is not defined (whatever that means). There are two quick fixes:
1) Check if row8[j] != null before using it.
2) Replace row8[j].getCell(3) with row8[j].getCell(3, Row.CREATE_NULL_AS_BLANK).
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has occurred because cell8[j] is null. You will need to debug to find out why.

On a side note, get into the habit of using braces for single line if conditions. The no braces style is horrible and prone to creating bugs.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!