Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:26:01+00:00 2026-06-03T21:26:01+00:00

I am iterating down a column of values until it hits a blank. I

  • 0

I am iterating down a column of values until it hits a blank. I need to gather the entire column and store it, and no other values. I’ve attempted to check for blank, null, 0, “”, and CELL_TYPE_BLANK (int = 3), and I cannot get it to avoid a null pointer exception. Code snippet and error are below. What can I do? This is not the entire method or program, just the relevant piece.

String s = list[i];
//find the directory from the list array to locate the file
InputStream input = new FileInputStream(s);
//create a new workbook object to hold the excel file
Workbook wb = new XSSFWorkbook(input);
//create an arbitrary starting location
int column = 2; //absolutely the correct number
int rownum = 10;
//get the value from the first sheet
org.apache.poi.ss.usermodel.Sheet insheet = wb.getSheetAt(0);       
//of the second columm
Row row = insheet.getRow(rownum);
//in the 11th row (arbitrary number used to reduce iterations and skip whitespace)
Cell cell = row.getCell(column); 
System.out.println("Skimming sheet: " + insheet.getSheetName());
//iterate until the very end of the column is found
System.out.println("Cell value B" + (rownum-1) +  ": " + cell);

//3 denotes CELL_TYPE_BLANK
while (cell.getCellType() != 3 ) {
    //go to the next location
    //update to the next cell
    System.out.println("Cell value B" + rownum +  ": " + cell);
    row = insheet.getRow(rownum);
    if(row.getCell(column).getCellType() != 3){
        cell = row.getCell(column); //error occurs here, line 241
    }
    rownum++;
}


Exception in thread "main" java.lang.NullPointerException
    at FileTest.skim(FileTest.java:241)
    at FileTest.main(FileTest.java:121)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:26:03+00:00Added an answer on June 3, 2026 at 9:26 pm

    You’re gettint the error because the row you’re trying to access is null, not the cell. You want to take a look in the Apache POI Iterator example.

    //taken from the example
    Sheet sheet = wb.getsheetat(0);
    for (Iterator<Row> rit = sheet.rowiterator(); rit.hasnext(); ) {
        Row row = rit.next();
        //now, based in your needs
        Cell cell = row.getCell(column);
        //do what you need with the row-column
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im iterating a list and getting hold of 2 fields Name and Url i
When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw a
I'm iterating over a JRE Collection which enforces the fail-fast iterator concept, and thus
I am iterating through a file and on each line I am looking for
I'm iterating through some objects and trying to set some properties that, apparently, don't
So if I am iterating using a foreach loop and I have a function
Having problems iterating. Problem has to do with const correctness, I think. I assume
I want avoid iterating over a nil array. My bad solution: if nil!=myArr myArr.each
Traditional task of iterating trough key set of std::map led me to another mess
I am currently iterating through a loop and redimensionalising my array every time I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.