Android Question Strange File not found error in API response!

I am getting strange 'java.io.FileNotFoundException: ' I am not dealing with any file. Please help!

Iam simply using this code to fetch Nutri score from free food facts API . I intend to use the ML kit Google Code Scanner to scan the barcode:
B4X:
Private Sub Button1_Click

    hitAPI("https://world.openfoodfacts.net/api/v2/product/301762401070?fields=product_name,nutriscore_data") ' the product bar code (301762401070) is deliberately  wrong to test API error response.
End Sub

Sub hitAPI (url As String)
    Dim dnr As Int =1
    Dim job As HttpJob
    pb.Visible=True
    'logoProgress("start")
    job.Initialize("",Me)
    job.Download(url)
    job.GetRequest.SetHeader("User-Agent", "com.personalapps.nutriscore - Android - Version 1.0 - www.testwebsite.com")
    Wait for (job) JobDone(job As HttpJob)
    'logoProgress("stop")
    If job.Success Then
        pb.Visible=False
        'start nutri_score code
        Dim parser As JSONParser
        parser.Initialize(job.GetString)
        Dim jRoot As Map = parser.NextObject
    
        Try
            Dim product As Map = jRoot.Get("product")
        Catch
            Log("JSON Parse Error" & LastException)
            xui.MsgboxAsync(LastException,"ERROR IN FETCHING DATA")
            Return
        End Try
.....

B4X:
Else
        Log(job.ErrorMessage)
        Dim parser As JSONParser
        parser.Initialize(job.ErrorMessage)
        Dim jRoot As Map = parser.NextObject
        Dim code As String = jRoot.Get("code")
        Dim status_verbose As String = jRoot.Get("status_verbose")
        Dim status As Int = jRoot.Get("status")
        lblNutriscore.Text=$"${status_verbose}"$&Chr(0xF06C)
        Log(job.GetString)
    End If
    job.Release
    
End Sub
 

aeric

Expert
Licensed User
Longtime User
Do not write Return and left the job not released.

B4X:
Sub hitAPI (url As String)
    'Dim dnr As Int =1
    Dim job As HttpJob
    'pb.Visible=True
    'logoProgress("start")
    job.Initialize("", Me)
    job.Download(url)
    job.GetRequest.SetHeader("User-Agent", "com.personalapps.nutriscore - Android - Version 1.0 - www.testwebsite.com")
    Wait For (job) JobDone(job As HttpJob)
    'logoProgress("stop")
    If job.Success Then
        'pb.Visible=False
        Log(job.GetString)
        Try
            'start nutri_score code
            Dim parser As JSONParser
            parser.Initialize(job.GetString)
            Dim jRoot As Map = parser.NextObject
            Dim product As Map = jRoot.Get("product")
            Log(product)
            lblNutriscore.Text = $"${product.Get("product_name")} ${Chr(0xF06C}"$)
        Catch
            Log("JSON Parse Error: " & LastException)
            xui.MsgboxAsync(LastException, "Error Parsing data")
            'Return
        End Try
    Else
        Log(job.ErrorMessage)
        Dim parser As JSONParser
        parser.Initialize(job.ErrorMessage)
        Dim jRoot As Map = parser.NextObject
        Dim code As String = jRoot.Get("code")
        Dim status_verbose As String = jRoot.Get("status_verbose")
        Dim status As Int = jRoot.Get("status")
        lblNutriscore.Text = $"${status_verbose} ${Chr(0xF06C}"$)
    End If
    job.Release
End Sub
 
Upvote 0
Thank you aeric. I remove the 'Return' but the error persisted. I noticed that I hadn't removed the ' Log(job.GetString)' . After removing that there was no error.

B4X:
Else
        Log(job.ErrorMessage)
        Dim parser As JSONParser
        parser.Initialize(job.ErrorMessage)
        Dim jRoot As Map = parser.NextObject
        Dim code As String = jRoot.Get("code")
        Dim status_verbose As String = jRoot.Get("status_verbose")
        Dim status As Int = jRoot.Get("status")
        lblNutriscore.Text=$"${status_verbose}"$&Chr(0xF06C)
        Log(job.GetString)
    End If
    job.Release
   
End Sub
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't think the issue with the Log. Maybe it fixed after a clean compilation.
Maybe, if it is job.Success = false then you don't use job.GetString.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…