rahim / nightwear

NightScout standalone Wear 2.0 watchface and complication
GNU General Public License v3.0
12 stars 9 forks source link

Fatal Exception when formatting blood glucose delta (German Locale) #35

Closed halbag closed 2 years ago

halbag commented 2 years ago

The watchface stopped working on my Samsung Galaxy 4 (German Locale) since introduciton of the blood glucose delta display. Apparently a number format issue causing to a fatal exception. Below the debug output from the device. Please notice, the device is in German locale, thus decimal separator is a comma (,) instead of a dot (.)


E/AndroidRuntime: FATAL EXCEPTION: main
    Process: im.rah.nightwear, PID: 9533
    java.lang.NumberFormatException: For input string: "12,2"
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
        at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
        at java.lang.Double.parseDouble(Double.java:538)
        at im.rah.nightwear.BloodGlucoseDelta.roundedMmol(BloodGlucoseDelta.kt:23)
        at im.rah.nightwear.BloodGlucoseDelta.inMmol(BloodGlucoseDelta.kt:15)
        at im.rah.nightwear.BloodGlucoseDeltaPresenter.prefix(BloodGlucoseDeltaPresenter.kt:22)
        at im.rah.nightwear.BloodGlucoseDeltaPresenter.toString(BloodGlucoseDeltaPresenter.kt:13)
        at java.lang.String.valueOf(String.java:2924)
        at java.lang.StringBuilder.append(StringBuilder.java:132)
        at kotlin.jvm.internal.Intrinsics.stringPlus(Intrinsics.java:20)
        at im.rah.nightwear.BloodGlucoseService.refresh$lambda-3(BloodGlucoseService.kt:126)
        at im.rah.nightwear.BloodGlucoseService.$r8$lambda$UVmqT0pBzT_1_iKnwO7sULO88-A(Unknown Source:0)
        at im.rah.nightwear.BloodGlucoseService$$ExternalSyntheticLambda1.onResponse(Unknown Source:4)
        at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:82)
        at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:29)
        at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:102)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:246)
        at android.app.ActivityThread.main(ActivityThread.java:7690)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
I/Process: Sending signal. PID: 9533 SIG: 9
halbag commented 2 years ago

As a quick fix; changing BloodGlucoseDelta.roundedMmol to the following helped me

    private fun roundedMmol(bg: BloodGlucose): Double {
        val mmol : Double = bg.glucoseLevel_mgdl / BloodGlucose.MMOLL_TO_MGDL
        val bd : BigDecimal = BigDecimal.valueOf(mmol).setScale(1, RoundingMode.HALF_UP)
        return bd.toDouble()
    }
rahim commented 2 years ago

Thanks for the report and suggested fix @halbag, I'll prioritise getting this addressed.

rahim commented 2 years ago

That should rollout to play store shortly as version 1.3.2.

Do let me know if you spot any more issues.