Android Question Read file and Math Function

Tilesoft

Member
Hi,
My app must Download a file > then read it (a number) > then (number+1=result) > write result to same file.
But i get some errors. My code is:
B4X:
Sub Globals
    Dim NumberVar As Int
    Dim NumberMath As Int
End Sub

Sub Button1_Click
    Dim j As HttpJob 'redim and initialize
    j.Initialize("", Me)
    j.Download("https://x.ir/number.txt")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim out1 As OutputStream = File.OpenOutput(File.DirInternal, "number.txt", False)
        File.Copy2(j.GetInputStream, out1)
        out1.Close '<------ very important
        If File.Exists(File.DirInternal, "number.txt") = True Then
            Log("yes")
            NumberVar=File.ReadString(File.DirInternal, "number.txt")
            Log(NumberVar)
            NumberMath=NumberVar+1
            File.WriteString(File.DirInternal, "number.txt", NumberMath)
            Log(NumberMath)
        End If
        'StartActivity(Post_Publish)
    End If
    j.Release
End Sub

And errors:
B4X:
number_download$ResumableSub_Button1_Clickresume (java line: 450)
java.lang.NumberFormatException: empty String
    at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
    at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.lang.Double.parseDouble(Double.java:538)
    at lila.project.number_download$ResumableSub_Button1_Click.resume(number_download.java:450)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:207)
    at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1178)
    at android.os.Handler.handleCallback(Handler.java:883)
    at android.os.Handler.dispatchMessage(Handler.java:100)
    at android.os.Looper.loop(Looper.java:224)
    at android.app.ActivityThread.main(ActivityThread.java:7561)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:995)
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
What does this line show in the Log ...
B4X:
            Log(NumberVar)
It looks as though it is not finding the numerical value that you expect. That would explain this error message ...
java.lang.NumberFormatException: empty String
 
Upvote 0
Top