Picker issues

30 views
Skip to first unread message

Rubén V

unread,
Jan 13, 2021, 9:47:24 PM1/13/21
to CodenameOne Discussions
Hi,

I need to move the selected date in the picker component to a "Long" type field. To do this I use the "getDuration ()" method and in the debugger it shows the message "[EDT] 0: 2: 18,194 - Exception: java.lang.ClassCastException - java.util.Date cannot be cast to java.lang.Long "

If I am doing something wrong I would like you to tell me which is the correct way.

Thanks

Shai Almog

unread,
Jan 13, 2021, 10:04:49 PM1/13/21
to CodenameOne Discussions
Hi,
getDuration will work for a picker of type duration.
If you want to convert a date to long just use getTime() on the resulting date object.

Rubén V

unread,
Jan 13, 2021, 11:25:02 PM1/13/21
to CodenameOne Discussions
Hi,

According to the documentation the "getTime ()" method returns an integer. Provide the following simple instruction:

int i = pkTiempo.getTime();
 
and Send the following error: 

[EDT] 0:1:17,977 - Exception: java.lang.ClassCastException - java.util.Date cannot be cast to java.lang.Integer

Hannah R

unread,
Jan 14, 2021, 10:19:45 AM1/14/21
to CodenameOne Discussions
Get the Date from your picker first, and then do getTime() from this date. 
Something like this
date.getTime(). 

Hannah R

unread,
Jan 14, 2021, 10:23:39 AM1/14/21
to CodenameOne Discussions

So you basically need  int i = pkTiempo.getDate().getTime();

Rubén V

unread,
Jan 14, 2021, 10:58:34 AM1/14/21
to CodenameOne Discussions
Thanks
Reply all
Reply to author
Forward
0 new messages