• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

Help required for this program

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, please find the below program iam getting the exception


Basically iam try to the format the string[] , this string[] should be different date pattern.



Iam getting the following exception :-

Exception in thread "main" java.lang.IllegalArgumentException
at java.util.Date.parse(Unknown Source)
at java.util.Date.<init>(Unknown Source)
If i use try catch block iam getting the compilation error

StringToDate.java:17: exception java.text.ParseException is never thrown in body
of corresponding try statement
}catch(ParseException pe)

Thanks,
Sridhar.R

 
Ranch Hand
Posts: 598
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Exception explains the problem. Check the format of the dates you are supplying to formatter.
 
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi sri,

You are using wrong date format other than "05/01/2007".Check it.


Cheers Munees
MyBlog
 
Marshal
Posts: 78659
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please read this.
 
Sridhar Ranganthan
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one please help me to resolve this program.

Thanks
 
Ranch Hand
Posts: 317
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the javadocs for the Date constructor with a String parameter

the only characters permitted within s are these ASCII characters:

abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789,+-:/

and whitespace characters.



If the number is followed by whitespace, a comma, a hyphen, or end of string, then if an hour has been recognized but not a minute, it is regarded as a minute; otherwise, if a minute has been recognized but not a second, it is regarded as a second; otherwise, it is regarded as a day of the month.



The first item in the Array is interpreted to be hour minute and second and thus an exception is thrown.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sridhar Ranganthan wrote:can any one please help me to resolve this program.


What is exactly the problem you are trying to solve?

Your program parses strings into Date objects. It expects the strings to be in the format "dd/MM/yyyy". Then you put in strings with different formats. Obviously if the string doesn't match the format, you get an exception - that's to be expected.

So, what are you looking for, a program that can parse all those different strings in different formats?

You can catch the ParseException and try to parse the string with a different format, until it parses without an exception.
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic