File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Calendar woes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar woes" Watch "Calendar woes" New topic
Author

Calendar woes

Andrew McLaren
Ranch Hand

Joined: May 27, 2005
Posts: 33
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

Joined: Aug 31, 2004
Posts: 11343

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.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Richard Anderson
Ranch Hand

Joined: May 20, 2005
Posts: 61
I think you need to set the ERA property in the GregorianCalendar object. Take a look at Calendar - ERA


-Rich, SCJP 1.4
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

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

Joined: May 27, 2005
Posts: 33
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar woes