• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DateField.getDate() returns null?

 
Shuai Liu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am using a DateField to let user enter a time field. It looks like the getDate() method always return null when the user enters any time prior to the prepopulated date of the DateField object.

In form init method I set the time to be current time


say if current time is 15:00 and user enters in 14:30, getDate() method will return null


and it works fine when user enters a time that is later than 15:00. Why?

Please help. Thank you!
 
Tiger Meng
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check the source code of DateField to find out why.
 
arvind doraiswamy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure you are entering the date in the correct format .To check out whether its just the date use the DateFormat class methods and also the java.util.date . 1 of these 2 has stuff which will get you your system date for you (i forget which 1..oops).I presume that all you need is a date object returned properly so you can proceed with the rest of your code.Gud Luck...n hope it helps
Arvind
 
arvind doraiswamy
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh...and on hindsight...have you allocated memory for the timeIn object..try explicitly allocating it memory.
java.util.Date timeIn=new java.util.Date();
and just 1 more thing...i think getDate() gets you your system date .So use the string that is returned from getDate() in your code and try....
arvind
 
Shuai Liu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by arvind doraiswamy:
oh...and on hindsight...have you allocated memory for the timeIn object..try explicitly allocating it memory.
java.util.Date timeIn=new java.util.Date();

What difference does that make? And yes, the input string is in correct format.
Thanks.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which device are we talking about here? Or is it Sun WTK? It surely sounds like a bug.
 
Shuai Liu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply.

My target device is Motorola i58sr, which is MIDP1.0 compatible.
My IDE is Websphere Device Developer 5.6 and I am using the bundled Nokia phone emulator to do testing.
I get same result from both the emulator and the phone.

I just tried to run it on a Treo600 (Palm OS 5) simulator, and it works w/o any problems! I will be shocked if this is indeed a bug because it's such a simple operation and MIDP1.0 has been released for more than 3 years?

Thanks again.
 
Michael Yuan
author
Ranch Hand
Posts: 1427
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it might be a bug in Sun's HotSpot VM implementation which device manufacturers often based their device VM upon. I would suggest you to try some of Nokia's "real" emulators (e.g., the 7210 and 6230 SDKs. NOT the "concept SDKs").

Also, just to make sure, do you know for sure that the error was caused by the null date? How did you test this on device when there is no exception trace? In your application flow, you can test if the Date is null and display a custom alert box if it is.
 
Shuai Liu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure if using different emulator will help me for the MIDlet doesn't work on my physical phone (Motorola i58sr) itself either?

Yes, I am 99.99% sure the error was caused by the null date. I wrote another simple test MIDlet which has only a DateField, a TextField and a Command. When the command is clicked, I display the return value of getDate() method on the TextField (display "null" if it's null) and I am getting consistent result as I described in my original post: It returns null under generic Nokia emulator and correct result under Treo600 simulator...

I also tried remote debugging on the Motorola phone, but didn't see any other exception that seemed related.

Thanks
[ July 07, 2004: Message edited by: Shuai Liu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic