personalapps
Member
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:
.....
Error occurred on line: 301 (HttpJob)
java.io.FileNotFoundException: /data/user/0/com.personalapps.nutriscore/cache/1: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:574)
at java.io.FileInputStream.<init>(FileInputStream.java:160)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:215)
at com.personalapps.nutriscore.httpjob._getstring2(httpjob.java:471)
at com.personalapps.nutriscore.httpjob._getstring(httpjob.java:142)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
at anywheresoftware.b4a.BA$2.run(BA.java:395)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:211)
at android.os.Looper.loop(Looper.java:300)
at android.app.ActivityThread.main(ActivityThread.java:8432)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:560)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:274)
at libcore.io.ForwardingOs.open(ForwardingOs.java:563)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:8310)
at libcore.io.IoBridge.open(IoBridge.java:560)
... 23 more
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