Android Question ERROR in HttpJob: NullPointerException:.... on a null object reference

PierPaduan

Active Member
Licensed User
Longtime User
Hi,
I have an HttpJob where I'm trying to set the header in the following way.
LastToken is sent from the server to the client.

B4X:
    Dim TokenHeaderName As String = "Authorization"
 
    Dim j2 As HttpJob
    j2.Initialize("send", Me)
    j2.GetRequest.SetHeader(TokenHeaderName, LastToken)
    j2.PostString(link_server, StringaJSON )

but I obtain the following error.

Any suggestion to fix this problem?
Thanks a Lot to everyone.
Best regards.

Error occurred on line: 83 (HttpJob)
java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.http.client.methods.HttpRequestBase.setHeader(java.lang.String, java.lang.String)' on a null object reference
at anywheresoftware.b4a.http.HttpClientWrapper$HttpUriRequestWrapper.SetHeader(HttpClientWrapper.java:449)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:742)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at it.ritmo.setandgopro.service2._pacchettizza_e_spedisci_sendlist(service2.java:863)
at it.ritmo.setandgopro.service2._spedizione_sendlist(service2.java:842)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:697)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at anywheresoftware.b4a.BA$2.run(BA.java:328)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5951)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
 

DonManfred

Expert
Licensed User
Longtime User
Did you marked okhttp library too in your project?
 
Upvote 0

PierPaduan

Active Member
Licensed User
Longtime User
Thanks Don, but I cannot switch to new okhttps because I use an old version of B4A that don't have those libs in the internal libs.

Any other suggestion?
Thanks
 
Upvote 0
Top