Android Question Why i getting this Error

Alhootti

Active Member
B4X:
Logger connected to: emulator-5554
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
** Receiver (bootstartsvc) OnReceive **
*** Service (starter) Create ***
** Service (starter) Start **
** Service (bootstartsvc) Create **
bootatstartsvc.Service_create()
** Service (bootstartsvc) Start **
bootatstartsvc.Service_Start()
** Activity (main) Create, isFirst = true **
main_ramdan_left (java line: 2520)
java.text.ParseException: Unparseable date: "30/02/2025" (at offset 10)
    at java.text.DateFormat.parse(DateFormat.java:555)
    at anywheresoftware.b4a.keywords.DateTime.DateParse(DateTime.java:148)
    at Ta.Clo.main._ramdan_left(main.java:2520)
    at Ta.Clo.main._activity_create(main.java:672)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at Ta.Clo.main.afterFirstLayout(main.java:105)
    at Ta.Clo.main.access$000(main.java:17)
    at Ta.Clo.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
main_ramdan_left (java line: 2520)
java.text.ParseException: Unparseable date: "30/02/2025" (at offset 10)
    at java.text.DateFormat.parse(DateFormat.java:555)

im using this code :
B4X:
Private Sub Ramdan_Left
    Dim LeftRam As String
    If Hij_Mon >= 10 And Hij_Mon <= 12 Then
        Hij_Year = Hij_Year + 1
    End If
    Dim Meladi As List = HijriConverter.HijriToGregorian(Hij_Year,"09","01" )
    LeftRam =  NumberFormat(Meladi.Get(0), 2 ,0) & "/" & NumberFormat(Meladi.Get(1), 2 ,0) & "/" & Meladi.Get(2)
    Dim diff As Period
    DateTime.DateFormat="dd/MM/yyyy"
    diff = DateUtils.PeriodBetweenInDays(DateTime.Now ,DateTime.DateParse(LeftRam))
    LeftRam = NumberFormat(diff.Days + 2,0,0) '
    ASClock3.MiddleText = "   " & LeftRam
    Label30.Text = "Left : "
    Label37.Visible = True
End Sub
 

Alhootti

Active Member
I'm using this lab:
B4X:
Sub HijriToGregorian( Y As Int,M As Int,D As Int) As Long
    Dim jd As Long
    Dim I As Long
    Dim N As Long
    Dim J As Long
    Dim K As Long
    Dim H As Long

    jd = Fix((11 * Y + 3) / 30) + 354 * Y + 30 * M - Fix((M - 1) / 2) + D + 1948440 - 385
    If jd > 2299160 Then
        I = jd + 68569
        N = Fix((4 * I) / 146097)
        I = I - Fix((146097 * N + 3) / 4)
        H = Fix((4000 * (I + 1)) / 1461001)
        I = I - Fix((1461 * H) / 4) + 31
        J = Fix((80 * I) / 2447)
        D = I - Fix((2447 * J) / 80)
        I = Fix(J / 11)
        M = J + 2 - 12 * I
        Y = 100 * (N - 49) + H + I
    Else
        J = jd + 1402
        K = Fix((J - 1) / 1461)
        I = J - 1461 * K
        N = Fix((I - 1) / 365) - Fix(I / 1461)
        H = I - 365 * N + 30
        J = Fix((80 * H) / 2447)
        D = H - Fix((2447 * J) / 80)
        H = Fix(J / 11)
        M = J + 2 - 12 * H
        Y = 4 * K + N + H - 4716
    End If
    DateTime.DateFormat="dd/MM/yyyy"
    Return DateTime.DateParse(D&"/"&M&"/"&Y)
End Sub
Sub GregorianToHijri(TheDate As Long) As List
    Dim jd As Long
    Dim I As Long
    Dim N As Long
    Dim J As Long
  

    Dim D As Long
    Dim M As Long
    Dim Y As Long

    D = DateTime.GetDayOfMonth( TheDate)
    M = DateTime.getMonth(TheDate)
    Y = DateTime.GetYear(TheDate)
    If ((Y > 1582) Or ((Y = 1582) And (M > 10)) Or ((Y = 1582) And (M = 10) And (D > 14))) Then
        jd = Fix((1461 * (Y + 4800 + Fix((M - 14) / 12))) / 4) + Fix((367 * (M - 2 - 12 * (Fix((M - 14) / 12)))) / 12) - Fix((3 * (Fix((Y + 4900 + Fix((M - 14) / 12)) / 100))) / 4) + D - 32075
    Else
        jd = 367 * Y - Fix((7 * (Y + 5001 + Fix((M - 9) / 7))) / 4) + Fix((275 * M) / 9) + D + 1729777
    End If
    I = jd - 1948440 + 10632
    N = Fix((I - 1) / 10631)
    I = I - 10631 * N + 354
    J = (Fix((10985 - I) / 5316)) * (Fix((50 * I) / 17719)) + (Fix(I / 5670)) * (Fix((43 * I) / 15238))
    I = I - (Fix((30 - J) / 15)) * (Fix((17719 * J) / 50)) - (Fix(J / 16)) * (Fix((15238 * J) / 43)) + 29
    M = Fix((24 * I) / 709)
    D = I - Fix((709 * M) / 24)
    Y = 30 * N + J - 30
    Return Array (Y,M,D)
End Sub
Sub Fix(arg As Int) As Int
    Return Ceil(arg )
End Sub
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
This code is not doing what you think it is doing; you are converting the argument to an integer before you even execute the statement ...
B4X:
Sub Fix(arg As Int) As Int
    Return Ceil(arg )
End Sub
You don't need to use it. Replace it everywhere as follows :
B4X:
N = Ceil((I - 1) / 10631)
That might not be your only error, of course.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
You don't need to use it.
Depends. Probably have to look at the resulting Java source, but since Ceil returns a double and the author may want to multiply INTs instead of doubles, he may choose to
B4X:
Sub Fix(arg As Double) As Int
   Return Ceil(arg)
End Sub
Of course in the grand scheme of things your solution may be correct if the differences are too small to be exasperated by the multiplication. In the end, the author is dealing with date conversion and, especially the one he seems to attempt, are complex as can be.

Link: https://stackoverflow.com/questions/31792256/get-a-gregorian-date-from-hijri-date-strings
 
Upvote 0
Top