• Post Reply Bookmark Topic Watch Topic
  • New Topic

NumberFormatException

 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I'm trying to read a property from a properties file which happens to be a date; 2001-02-02. After converting the String to long with the following snippet,
long expDtLong = Long.parseLong(PropFile.getProperty("EXDATE"));
java.sql.Date expDate = new java.sql.Date(expDtLong);
I get this error:
Exception in thread "main" java.lang.NumberFormatException: 2001-02-02
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
Any idea what I need to do or what I'm missing? I thought I could read anythingn from s Properties file, looks like I'm wrong!
Thanks in advance for your help.
 
raghavender rao
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ther,,
first of all
u cant store other than numbers in long isnt??/

so u cant say long l = 2001-02-02;
at the runtime it wil definitely raise java.lang.NumberFormatException:

anyway u can modify ur code as below to display date...

long expDtLong = 992337203674L;

java.sql.Date expDate = new java.sql.Date(expDtLong);

SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy");

System.out.println("The Value of Date is "+expDtLong);


String s = sdf.format(expDate);

System.out.println("The Date is "+s);

and dont forget to import java.text.*; for further reference please refer the package.....

Rao
 
Med Shabe
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply, however I canot do this: long expDtLong = 992337203674L;
because ther value is being read from a properties file.
If I do this
java.text.SimpleDateFormat sp = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.sql.Date myDate = sp.parse(ICONFEED.getProperty("EXDATE"));
I get this:
Explicit cast needed to convert java.util.Date to java.sql.Date.
And if i do this:
java.util.Date myDate = sp.parse(ICONFEED.getProperty("EXDATE"));
I get this:
java.lang.NullPointerException
 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Try this;
String sDate = PropFile.getProperty("EXDATE");
java.sql.Date expDate = java.sql.Date.valueOf(sDate);
Cheers

Originally posted by Med Shabe:
Hello,
I'm trying to read a property from a properties file which happens to be a date; 2001-02-02. After converting the String to long with the following snippet,
long expDtLong = Long.parseLong(PropFile.getProperty("EXDATE"));
java.sql.Date expDate = new java.sql.Date(expDtLong);
I get this error:
Exception in thread "main" java.lang.NumberFormatException: 2001-02-02
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
Any idea what I need to do or what I'm missing? I thought I could read anythingn from s Properties file, looks like I'm wrong!
Thanks in advance for your help.

 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Try this;
String sDate = PropFile.getProperty("EXDATE");
java.sql.Date expDate = java.sql.Date.valueOf(sDate);
Cheers

Originally posted by Med Shabe:
Hello,
I'm trying to read a property from a properties file which happens to be a date; 2001-02-02. After converting the String to long with the following snippet,
long expDtLong = Long.parseLong(PropFile.getProperty("EXDATE"));
java.sql.Date expDate = new java.sql.Date(expDtLong);
I get this error:
Exception in thread "main" java.lang.NumberFormatException: 2001-02-02
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
Any idea what I need to do or what I'm missing? I thought I could read anythingn from s Properties file, looks like I'm wrong!
Thanks in advance for your help.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!