Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • 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
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Read Excel Sheet

 
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to read the excel sheet. I've used POI library.


I'm getting null pointer exception at in for loop.

I want to display all contents from excel sheet.
 
Marshal
Posts: 14288
237
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you're getting the NPE in the for loop? If anything, I would expect an NPE way back on Line 4 before you'd get one on Line 10. Is that a complete listing or did you omit some code in between Line 4 and Line 10?
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
line 4 not returning NPE. Now i found that the excel sheet I'm reading has first 3 rows empty. so it is returning NPE at line 10. How to read the remaining rows?
 
Junilu Lacar
Marshal
Posts: 14288
237
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JavaDocs say that getRow returns null if the row is not defined. Are you sure that the NPE is thrown on Line 10 and not Line 11? That's where the NPE would be thrown if getRow(i) returns null.
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My mistake, getCell() method is returning NPE... well then how I'm i supposed to get further rows even if there is an empty row in the middle.
 
Ranch Hand
Posts: 47
MyEclipse IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



this might help...
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome To Ranch buddy
Well sheet.getColumns() and sheet.getRows() are in JXL library... I want to do it in Apache's POI library..
 
Ankit Dan
Ranch Hand
Posts: 47
MyEclipse IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Rooge wrote:Welcome To Ranch buddy
Well sheet.getColumns() and sheet.getRows() are in JXL library... I want to do it in Apache's POI library..



....ok let me read your query again then...
 
Ankit Dan
Ranch Hand
Posts: 47
MyEclipse IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the static class Row.MissingCellPolicy



and pass Row.RETURN_NULL_AND_BLANK in the policy parameter
which will have missing cells returned as null, Blank cells returned as normal

was this helpful??
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
had seen it in documentation and tried but same exception...

 
Ankit Dan
Ranch Hand
Posts: 47
MyEclipse IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


try this




tell me if this works or not..
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First i dont know what will that return.. second dont know where do you want me to try it.
 
Ankit Dan
Ranch Hand
Posts: 47
MyEclipse IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Rooge wrote:First i dont know what will that return.. second dont know where do you want me to try it.



in your console output...
am i getting you right...your getCell() is throwing an NPE...



it just checks for the null you are getting in form of blanks. if null then print "" otherwise get the value..
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya getCell() is throwing an NPE... but even before i check for that condition it is throwing exception.. may be there is some other way to proceed..
 
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Rooge wrote:My mistake, getCell() method is returning NPE... well then how I'm i supposed to get further rows even if there is an empty row in the middle.


Am I missing something ? Why don't you just check if row is null before you use it
 
Prasad Rooge
Greenhorn
Posts: 25
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You got that right... damn its so simple
 
Ankit Dan
Ranch Hand
Posts: 47
MyEclipse IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Rooge wrote: You got that right... damn its so simple

 
That new kid is a freak. Show him this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!