Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar woes

 
Andrew McLaren
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to use a GregorianCalendar to set a schedule for a future time.
Here's what I am testing with so far:


Everything works until I try and print out the time (or do anything else with it). Then it barfs on me with this error:

java.lang.IllegalArgumentException: Invalid era

I have no clue what this means. What am I doing wrong?

Peace

Andrew
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe your problem is in the 2-argument version of the set method in Calendar. If you check the API, you'll see that the 2-argument version does not parallel the versions that take more arguments, and what you're actually doing is putting an invalid value in the ERA field.
 
Richard Anderson
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to set the ERA property in the GregorianCalendar object. Take a look at Calendar - ERA
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Richard Anderson:
I think you need to set the ERA property in the GregorianCalendar object...

The ERA field is valued with with setTime method (using the Date object). In this case, the problem occurs with the call to set(0,9), which appears to be re-valuing the ERA field with 9. Commenting out this line eliminates the error. However, the line after it (another call to the 2-argument version of set) is likely to produce unexpected results as well.
[ August 01, 2005: Message edited by: marc weber ]
 
Andrew McLaren
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by marc weber:
I believe your problem is in the 2-argument version of the set method in Calendar. If you check the API, you'll see that the 2-argument version does not parallel the versions that take more arguments, and what you're actually doing is putting an invalid value in the ERA field.



Sigh...excuse me while I crawl off under the rock of shame. I knew the set (0,9) method wasn't doing what I wanted. Apparently commenting that line out was beyond my meager abilities.

Thanks for your help!

Andrew
[ August 02, 2005: Message edited by: Andrew McLaren ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic