udg Expert Licensed User Longtime User Jan 17, 2023 #1 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" Code: Copy '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)
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" Code: Copy '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)
E emexes Expert Licensed User Longtime User Jan 17, 2023 #2 udg said: No problem to convert everything to long values, but why java looks at my string as a number? Click to expand... Use String method .CompareTo() https://www.b4x.com/android/help/core.html#string_compareto I too used to wonder why String comparison operators = and <> were implemented but < <= >= > were not. Last edited: Jan 17, 2023
udg said: No problem to convert everything to long values, but why java looks at my string as a number? Click to expand... Use String method .CompareTo() https://www.b4x.com/android/help/core.html#string_compareto I too used to wonder why String comparison operators = and <> were implemented but < <= >= > were not.
udg Expert Licensed User Longtime User Jan 17, 2023 #3 That's true. Converting original test to the following, works ok and doesn't need an explicit prior conversion to long values: Code: Copy 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.."
That's true. Converting original test to the following, works ok and doesn't need an explicit prior conversion to long values: Code: Copy 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.."