?
Solved

Java Calendar class - exception when using setTime()

Posted on 2004-09-27
1
Medium Priority
?
1,565 Views
Last Modified: 2008-03-04

Hi,
Can anyone see anything wrong with this while loop?

while (dateResultSet.next()) {                           
               Date directDebitDate = dateResultSet.getDate("direct_debit_date");                           
                         Calendar allowable = Calendar.getInstance();
                    Calendar directDebitDueDate = Calendar.getInstance();
                      
            /* set calendar value to 3 days time */                                                
                           allowable.add(Calendar.DATE, 3);                                                
                           directDebitDueDate.setTime(directDebitDate);
                           
                           /* if it falls before 3 days time it is classified as urgent */
                           if (directDebitDueDate.before(allowable))
                           {
                                 urgentPending ++;    
                                 System.out.println("Urgent pending count " + urgentPending);
                           }else
                           {
                                 regularPending ++;
                                 System.out.println("Regular pending count " + regularPending);
                           }                            
                           
                     }


 When i run it the results from of the system.outs come up fine but the setTime method causes the following exception

Caused by: java.lang.NullPointerException
      at java.util.Calendar.setTime(Calendar.java:902)
      ... 34 more
Caused by:
java.lang.NullPointerException
      at java.util.Calendar.setTime(Calendar.java:902)
      at ie.sentenial.business.database.MySQLDataManager.getClientCustomerStatuses(Unknown Source)
      at ie.sentenial.business.database.MySQLDataManager.getClientCustomerStatuses(Unknown Source)
      at ie.sentenial.application.actions.LoginAction.getClientCustomerStatusDetails(Unknown Source)
      at ie.sentenial.application.actions.LoginAction.execute(Unknown Source)
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)

Any ideas anyone???
0
Comment
Question by:fyness
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
KeithWatson earned 375 total points
ID: 12161853
It looks as as though there are null values in your database's direct_debit_date column. The fix for this would depend on your application. You could change the database to not allow null values and the problem won't arise (once you've populated your database correctly); however, if it's legal to have null values for the date in your application then you would need to ignore these in your piece of code, so:

while (dateResultSet.next()) {                        
              Date directDebitDate = dateResultSet.getDate("direct_debit_date");                        

               if (directDebitDate==null) {
                   continue;
                }

                       Calendar allowable = Calendar.getInstance();
                  Calendar directDebitDueDate = Calendar.getInstance();
                     
           /* set calendar value to 3 days time */                                          
                        allowable.add(Calendar.DATE, 3);                                          
                        directDebitDueDate.setTime(directDebitDate);
                       
                        /* if it falls before 3 days time it is classified as urgent */
                        if (directDebitDueDate.before(allowable))
                        {
                             urgentPending ++;    
                             System.out.println("Urgent pending count " + urgentPending);
                        }else
                        {
                             regularPending ++;
                             System.out.println("Regular pending count " + regularPending);
                        }                        
                       
                   }
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question