Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    1

    Unanswered: Suppressing NullPointerException

    I am trying to parse an array of Excel cells which is stored in cellsFirstColumn. When I try to print out some of the cells I am able to print out expected values that are non-null values. However, with null values, I am getting an Exception thrown and I want to turn it off. Can someone please help?

    Thanks.


    try
    {
    for (int m =0; m <= 1000; m++)
    {
    System.err.println(m);
    strGetCell = (String) cellsFirstColumn[m][0] ;
    strGetCell = strGetCell.toUpperCase();
    System.err.println(strGetCell);
    }
    }

    catch (Exception e)
    {
    System.err.println(e.getMessage()) ;
    System.err.println(e.toString());
    return 0 ;
    }
    finally
    {
    com.linar.jintegra.Cleaner.releaseAll();
    }

  2. #2
    Join Date
    May 2005
    Location
    San Antonio, Texas
    Posts
    134
    I am guessing you are getting the null exception on the strGetCell.toUpperCase() line?

    I know of no way to 'turn it off' but you can check for it to avoid the problem and move on to the next iteration.

    if(strGetCell != null){
    do stuff;
    }

    try/catch blocks will catch the error so that the system can deal with it, but the code that was executing (your for loop) will stop running once the error is thrown.

    you just end up with a lot of null checks in java
    Vi veri veniversum vivus vici
    By the power of truth, I, a living man, have conquered the universe

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •