B4J Question [SOLVED] Lost trying to get [server] jOkHttpUtils2 - server version working

JackKirk

Well-Known Member
Licensed User
Longtime User
In this thread:

https://www.b4x.com/android/forum/threads/server-jokhttputils2-server-version.124350/#content

Erel explains how to make jOkHttpUtils2 work in a non-UI server app.

Unfortunately it is a bit opaque for me.

On the line:

3. The library code calls Main.srvr.CreateThreadSafeMap. If you named your server object differently then you need to add such public global variable and assign it the server object.

In my ABMaterial app the server is:

Public Server As ABMServer

so to comply with 3. I added to the Main module of my app:

Public srvr As Server = Server.srvr

and I can see Server.srvr has a method CreateThreadSafeMap

However when I run the code in Debug mode I get a java.lang.NullPointerException at the line

TaskIdToJob = Main.srvr.CreateThreadSafeMap

in HttpUtils2Service

And I am stumped - any suggestions appreciated.
 

JackKirk

Well-Known Member
Licensed User
Longtime User
Sometimes my stupidity frightens me.

For the edification of anyone else who is equally blighted I will explain my error in detail.

My interpretation of Erel's note 3 was to just add:

Public srvr As Server = Server.srvr

in Main.Process_Globals

WRONG!!!

What you have to do is:

B4X:
Main

Sub Process_Globals

    ....

    Public Server As ABMServer

    ....

    Public srvr As Server

    ....

Sub AppStart (Args() As String)

    Realstart

    StartMessageLoop

End Sub

'This required because of:
'https://www.b4x.com/android/forum/threads/wait-for-not-work-as-in-documentation.146663/post-929835
'You must have a StartMessageLoop in a console app and you cannot use Wait For
'or Sleep inside AppStart (in console app)
'and "console app" = "non-UI app"
Sub Realstart

    ....

    'Whatever ABMServer initialization you require, e.g.:
    Private DonatorKey As String = ""
    Server.Initialize("", DonatorKey, "start")
    'Server.Port = 51042
    Server.PortSSL = 51044
    'If user needs to login, set to true - CheckLogin() method will be
    'called if user tries to login
    Server.NeedsAuthorization = False
    'First page of app
    Server.StartPage = "start_page"
    Server.CacheScavengePeriodSeconds = 15 * 30 ' 15 minutes
    Server.SessionMaxInactiveIntervalSeconds = 30 * 60 ' 30 minutes
'    Server.UploadFolder = "uploads"
'    Server.UploadMaxSize = 1024 * 1024

    'And finally...
    srvr = Server.srvr

And wonder of wonders it all works...
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…