Android Question Parse Date Error in ReleaseMode

bocker77

Active Member
Licensed User
Longtime User
For some strange reason I am getting this error only in Release mode. It works if I compile in Release mode and run it but when I end it and start it from the icon I get this error.

b4xmainpage$ResumableSub_GetGameNameresume (java line: 5820)
java.text.ParseException: Unparseable date: "05/14/2025"
at java.text.DateFormat.parse(DateFormat.java:362)
at anywheresoftware.b4a.keywords.DateTime.DateParse(DateTime.java:148)
at AA.Adjunct.b4xmainpage$ResumableSub_GetGameName.resume(b4xmainpage.java:5820)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:215)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:247)
at android.app.ActivityThread.main(ActivityThread.java:8676)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

The date looks just fine in the error message. I am almost positively it is something I am doing wrong in my code to create the error but can't seem to figure it out. Also not able to find any good hits on this error in the Forum.

B4X:
        Else     ' Restart an old game
            Dim t As Long
            strTempName = strTempName.Replace("*", "")
            t = DateTime.DateParse(strTempName)         <=== Errors out on this line
            DateTime.DateFormat = "EEE, MMM d, yyyy"
            strTempName = DateTime.Date(t)
        End If
        Speak("Playing game started on " & strTempName)   ' When it works strTempName has "Wed, May 5, 2025"

I can either delete this code fragment or hopefully get this fixed by Tuesday because that is when me and the boys continue our current Axis & Allies game!
 

emexes

Expert
Licensed User
Wrap it in a Try and display or Log DateFormat and strTempName when it fails.

Perhaps speed up the debugging process by temporarily hardcoding in the Unparseable date: "05/14/2025"
 
Upvote 0

emexes

Expert
Licensed User
Is the error occurring on the same phone that you develop on, or a different phone?

Perhaps the locale settings are different, and cause a different default date format.

Are you in a country that uses month-day-year date element ordering?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You are setting the date format to : DateTime.DateFormat = "EEE, MMM d, yyyy"
This is remembered, and when it tries to parse strTempName which looks like it is "05/14/2025" it will fail.
You haven't said if you have set the DateFormat previously in the app.
Set the DateTime.DateFormat correctly before parsing each different format.
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I will try all of your suggestions but my confusion is it was tested and working for months after Release. I did work on other parts of the program after this but nothing around these lines.

For emexes second question I reside in the US and was developed and is running on the same tablet that it was developed on which uses month, day, year. It's an older Samsung.

Just for reference, each game is stored in its own db and saved. Here is pertinant logging from progam.

Saved filename: Game: 05-14-2025.db
Stripped item name for B4XListTemplate: Game: 05-14-2025
Stripped & changed date: 05/14/2025
Parsed date: 1747195200000
Date Format : MMM d, yyyy
Final result: game started on May 14, 2025

Removed the "EEE," which appears to be causing the problem. I will research why this is causing my issue but I really don't need the day name after all. So Tuesday's game is on.

Thx guys for your suggestions!
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I did work on other parts of the program after this but nothing around these lines.
The date format is global and If you changed the date format elsewhere in the program and it's not explicitly set correctly before you try to use it in these lines, it could be the cause of the error. Anyway, glad you got it sorted.
 
Upvote 0

emexes

Expert
Licensed User
Date Format : MMM d, yyyy
Final result: game started on May 14, 2025

Bear in mind that MMM is different in different languages.

Also I vaguely remember that it's not even always 3 characters, eg the ninth month might show as "Sept" rather than "Sep"...
 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I found this link that I believe would work but did not try it. It uses AHLocal.

 
Upvote 0

bocker77

Active Member
Licensed User
Longtime User
I also checked to see if my Locale on the tablet changed but it is still intact, Eastern US timezone. Why it was working with the date string that I was feeding the format but then quit is still beyond me! I did find some hits on Stack Overflow concerning my issue but nothing that was matching the date string that I am using.
 
Upvote 0
Top