If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
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, 15: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, 10: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

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