Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Suppressing NullPointerException

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-08, 16:03
RedOrange RedOrange is offline
Registered User
 
Join Date: Aug 2008
Posts: 1
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();
}
Reply With Quote
  #2 (permalink)  
Old 08-27-08, 11:22
amthomas amthomas is offline
Registered User
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On