B4J Question Error downloading with jOkHttpUtils2

magarcan

Active Member
Licensed User
Longtime User
My code uses different httpjob in order to download several files. After some of them it always shows this error. Looks like it's reaching some limit, like a buffer overflown. I'm pretty sure it's related with httpjob I can't use each one more than 10 times.

This is the error but can't find the line is causing it.

Any idea?
B4X:
java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\Manu\AppData\Local\Temp\12 (Acceso denegado)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
    at anywheresoftware.b4a.BA$4.run(BA.java:196)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: C:\Users\Manu\AppData\Local\Temp\12 (Acceso denegado)
    at java.io.FileOutputStream.open0(Native Method)
    at java.io.FileOutputStream.open(FileOutputStream.java:270)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
    at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:371)
    at b4j.example.httputils2service._hc_responsesuccess(httputils2service.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    ... 8 more

Here you have the code in order to test it:
B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private MainForm As Form
    Private Button1 As Button
  
    Dim job1 As HttpJob
  
    Dim i = 1 As Int
  
    Private TextArea1 As TextArea
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("main")     'Load the layout file.
    MainForm.Show
End Sub

Sub Button1_MouseClicked (EventData As MouseEvent)          
    'Start downloads
    job1.Initialize("Job1", Me)
    job1.Download("http://www.google.com")

End Sub

Sub JobDone (Job As HttpJob)
    If Job.Success = True Then
        Log("Downloaded " & i & " times")
    Else
        Log("Error: " & Job.ErrorMessage)
    End If
    Job.Release
          
    If i = 15 Then        '15 times  
        Log("End")
    Else
        i = i+1
        job1.Download("http://www.google.com")
    End If
End Sub
 
Last edited:

magarcan

Active Member
Licensed User
Longtime User
set the Temp directory

B4X:
HttpUtils2Service.TempFolder
for your used OS
Thank you very much! Before set the temp folder you also have to initialize the service ;)
B4X:
HttpUtils2Service.Initialize
HttpUtils2Service.TempFolder = File.DirApp
 
Upvote 0
Top