Bug? NumberFormatException on a string date

udg

Expert
Licensed User
Longtime User
Hi,
I can't say if things were always like this, but recently I found that comparing two string whose values are dates causes the error in the subject

java.lang.NumberFormatException: For input string: "2023-01-18"

B4X:
'm1 is a map read as the Value of an XCLV item
Dim status As Int = m1.Get("ostatus")
Dim oday As String = m1.Get("oday")
If (status = 0) And (oday>= B4XPages.MainPage.AppGlobals.TestDay) Then   'TestDay = "2023-01-18"

No problem to convert everything to long values, but why java looks at my string as a number?

Update: even writing like this will fail: oday.As(String)>= B4XPages.MainPage.AppGlobals.TestDay.As(String)
 

udg

Expert
Licensed User
Longtime User
That's true. Converting original test to the following, works ok and doesn't need an explicit prior conversion to long values:
B4X:
If (status = 0) And  (oday.CompareTo(B4XPages.MainPage.AppGlobals.TestDay)>=0)  Then

Maybe a warning like "operator not applicable to string type" or something like that could be useful.
Anyway, now the error message is clearer to me. It means ("since >= operator applies to numbers and operands aren't, than here its is your error.."
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…