HttpUtils Problem

salmander

Active Member
Licensed User
Longtime User
hello All,

I have recently started working with HttpUtils, as I was working with manual HttpClient method earlier. Now after few testing I am encountering this error.
B4X:
Starting Job: search
httputils_internalcheckifcanstart (java line: 131)
java.lang.NullPointerException
   at com.home.cafiq.test.httputils._internalcheckifcanstart(httputils.java:131)
   at com.home.cafiq.test.httputils._downloadlist(httputils.java:50)
   at com.home.cafiq.test.httputils._download(httputils.java:43)
   at com.home.cafiq.test.search._btnsearch_click(search.java:921)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
   at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:54)
   at android.view.View.performClick(View.java:3538)
   at android.view.View$PerformClick.run(View.java:14330)
   at android.os.Handler.handleCallback(Handler.java:607)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:156)
   at android.app.ActivityThread.main(ActivityThread.java:5005)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

any help much appreciated?
 

salmander

Active Member
Licensed User
Longtime User
By playing around with the code more, I have found a clue. I have several activities and services which uses HttpClients to download data from the server in my project, and I have started converting HttpClient method to HttpUtils method. After successfully converting one Activity, when I tried using the httpUtils in service module, it was causing problems.

Can I not use httpUtils from a service module?
i have configured the service module like this.
B4X:
'Service module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
'   Dim httpClient1 As HttpClient
   Dim app_version, server_version As String
'   Dim url As String
   Dim preferences_set As Boolean
   
   HttpUtils.CallbackActivity = "RemoteManagement" ' Service Name
   HttpUtils.CallbackJobDoneSub = "JobDone"
   HttpUtils.CallbackUrlDoneSub = "URLdone"
   Dim MainUrl As String
End Sub


sub functionOne
'   httpClient1.InitializeAcceptAll("httpClient1")
'   Dim req As HttpRequest
'   req.InitializeGet(url & "update.txt")
'   httpClient1.Execute(req, 1)
   MainUrl = url & "update.txt"
   HttpUtils.Download("checkUpdate", MainUrl)
end sub
.
.
.
.
.
etc

But i think in one post it is mentioned that you can't run two jobs at one time. So this service runs in the background of the activity, could this be the problem? If yes, how can I re-solve it please?

And presumably it is ok to use the Service Name in "HttpUtils.CallbackActivity" method.
As mentioned in my earlier post I was using HttpClient Method to communicate with the servers. It was all working fine until I started using Android 4.0 layout. Every time my app tries to connect to the server, it was giving me the error message. Then I read in one post that you can't use Http communication on the main thread, Android 4.0 doesn't allow it and was suggested to use the HttpUtil code module.

Help me please.
 
Upvote 0

DeerBear

Member
Licensed User
Longtime User
Can I not use httpUtils from a service module?

Take this with a pinch of salt, I am no expert and I might be wrong.
However, the HTTPUtils code module uses a service to
actually do downloads and I think this could potentially be related to the
issues you're having.

Regards,

A
 
Upvote 0

salmander

Active Member
Licensed User
Longtime User
Thanks for your reply. I don't understand why there would be a problem calling a service module from a service module.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…