B4J Question help on strange error message

madru

Active Member
Licensed User
Longtime User
Hi,

what does this mean? this comes up after making the following HTTP request.

java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\dev\AppData\Local\Temp\2 (Access is denied)
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$174(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$175(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$149(WinApplication.java:191)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.FileNotFoundException: C:\Users\dev\AppData\Local\Temp\2 (Access is denied)
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:67)
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

B4X:
Sub MakeRPCRequest( method As String, arguments As List) As Boolean


    Dim IPS_URI As String
    Dim Send As String
    Dim j As HttpJob
    Dim myarguments As String
    j.Initialize("j", Me)
    Dim a As Int
   
    For a = 0 To arguments.Size - 1
        myarguments = myarguments & arguments.Get(a)   
    Next

    IPS_URI = "http://" & "192.168.1.154" & ":3777/api/"
    Send = "{" & Chr(34) & "jsonrpc" & Chr(34) & ":" & Chr(34) & "2.0" & Chr(34) & "," _
    & Chr(34) & "method" & Chr(34) & ":" & Chr(34) & method & Chr(34) & "," _
    & Chr(34) & "params" & Chr(34) & ":[" & myarguments & "]," _
    & Chr(34) & "id" & Chr(34) & ":" & Chr(34) & "NULL" & Chr(34) & "}"

    Log(Send)
    Try
        j.PostString(IPS_URI, Send)
        j.GetRequest.SetContentType("application/json")

    Catch 
        Return False
    End Try

End Sub

THX

Guido
 

Cableguy

Expert
Licensed User
Longtime User
This line says it all!!

java.io.FileNotFoundException: C:\Users\dev\AppData\Local\Temp\2 (Access is denied
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
yes, saw that one but that path is accessible. if the http request is issued for the 2nd time it does work without an error
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
it may be a time out issue, have you tried to enclosure the file access lines inside a try/catch ?
that way you could make a small delay between first and second try to access it
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi,

no it is not a timing issue , I still have no idea why the 2nd call ends in "Access is denied"
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
OK, little update. The error only occurs on Windows, Linux & OS X are not showing that behavior.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Please learn how to use smart strings literal: https://www.b4x.com/android/forum/threads/50135/#content
B4X:
Send = $"{"jsonrpc":"2.0", "method": ${method} ,
  "params":[${myarguments}],
  "id":"NULL"}"$

Or better:
B4X:
Dim jg As JSONGenerator
jg.Initialize(CreateMap("jsonrpc": method, "params": Array(...), _
   "id": Null))
Log(jg.ToPrettyString(4))

I'm not sure why you get this error (might be the antivirus fault). You can try to use a different folder for the temporary files:
B4X:
j.Initialize(...)
HttpUtils2Service.TempFolder = File.DirData("MyApp")
 
Upvote 0

madru

Active Member
Licensed User
Longtime User
Hi,

will have a look :)

moving the TempFolder does work, I will do some investigation later ....

as always THX a lot
 
Upvote 0
Top