Android Question Attempt to write to field 'boolean anywheresoftware.b4a.samples.httputils2.httpjob._success'

TIMX

Member
Licensed User
Hi, Please I need some lights,

I include the resumable subs to get register from remote database, but the problem persist.
Exactly occurs when I click on Login from Main Activity to navigate to ModPrincipal and I click egain on return key an wait 30 seconds in Main Activity then exception appear.
Note the http request is in the Main Activity_Resume, it is called fnVerificaServerUp

ResponseError. Reason: java.net.SocketTimeoutException: failed to connect to apps.consenso.com.ec/190.63.153.138 (port 17178) after 30000ms, Response:
~e:java.lang.NullPointerException: Attempt to write to field 'boolean anywheresoftware.b4a.samples.httputils2.httpjob._success' on a null object reference
~e: at anywheresoftware.b4a.samples.httputils2.httputils2service._completejob(httputils2service.java:140)
~e: at anywheresoftware.b4a.samples.httputils2.httputils2service._hc_responseerror(httputils2service.java:160)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at java.lang.reflect.Method.invoke(Method.java:372)
~e: at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
~e: at anywheresoftware.b4a.BA$2.run(BA.java:360)
~e: at android.os.Handler.handleCallback(Handler.java:739)
~e: at android.os.Handler.dispatchMessage(Handler.java:95)
~e: at android.os.Looper.loop(Looper.java:145)
~e: at android.app.ActivityThread.main(ActivityThread.java:7007)
~e: at java.lang.reflect.Method.invoke(Native Method)
~e: at java.lang.reflect.Method.invoke(Method.java:372)
~e: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
~e: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

View attachment 69619
 

Attachments

Last edited:

TIMX

Member
Licensed User
The problem is when I leave the Main Activity I stop the service http with this sentences "StopService(HttpUtils2Service)", when i should use it or how i should use it?.
I use it because In some activities i send a remote server request but i don't recive the answer after that I navigate to an other activity then the answer arrive then request owner Activity appear in foreground.

I would like wait for the server answer only 5 or 10 seconds, but not 30 seconds, How i can do it?
 
Last edited:

TIMX

Member
Licensed User
Thanks for your answerb @DonManfred. It´s seems good, can you shere with me an example with interaction between Starter service and the activity?
 

DonManfred

Expert
Licensed User
Activity
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    CallSub2(Starter,"CheckGoogle",Me)
End Sub
Sub TheResult(result As String)
    Log("This is the result from the Service-okhttpcall:")
    Log(result)
End Sub

Starter
B4X:
public Sub CheckGoogle(callback As Object)
    Dim Job As HttpJob
    Job.Initialize("Job1",Me)
    
    Job.Download("https://google.com")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim result As String = j.GetString
        If IsPaused(callback) = False Then
            CallSub2(callback,"TheResult",result)
        End If
    Else
        ' Send the error to another sub if you want
    End If
    j.Release
End Sub
 

Attachments

Top