permaculture playing cards*
The moose likes Java in General and the fly likes Read Excel Sheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Read Excel Sheet" Watch "Read Excel Sheet" New topic
Author

Read Excel Sheet

Prasad Rooge
Greenhorn

Joined: May 28, 2012
Posts: 25

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.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

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?


Junilu - [How to Ask Questions] [How to Answer Questions]
Prasad Rooge
Greenhorn

Joined: May 28, 2012
Posts: 25

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
Bartender

Joined: Feb 26, 2001
Posts: 4458
    
    6

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

Joined: May 28, 2012
Posts: 25

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.
Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47




this might help...
Prasad Rooge
Greenhorn

Joined: May 28, 2012
Posts: 25

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

Joined: Aug 31, 2012
Posts: 47

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

Joined: Aug 31, 2012
Posts: 47

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

Joined: May 28, 2012
Posts: 25

had seen it in documentation and tried but same exception...

Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47



try this




tell me if this works or not..
Prasad Rooge
Greenhorn

Joined: May 28, 2012
Posts: 25

First i dont know what will that return.. second dont know where do you want me to try it.
Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47

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

Joined: May 28, 2012
Posts: 25

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..
Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
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

Joined: May 28, 2012
Posts: 25

You got that right... damn its so simple
Ankit Dan
Ranch Hand

Joined: Aug 31, 2012
Posts: 47

Prasad Rooge wrote: You got that right... damn its so simple
 
wood burning stoves
 
subject: Read Excel Sheet