Android Tutorial HttpUtils - Android web services are now simple!

Status
Not open for further replies.

hackhack

Active Member
Licensed User
Longtime User
So the getstring is only for text? I try to download a binary apk file, and the file is incomplete.
 

xalion

Member
Licensed User
Longtime User
I found anoher problem for httputils.
My phone is HTC Incredible 2. when I powered off my device and powered on then. It shows Force Closed my application error.
I checked the log:

06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfo ++
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfo name=web.xasyu.cn
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfoImpl ++
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfoImpl result == 0 && addressList
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfoImpl: case AF_INET:
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfoImpl addressList
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfoImpl --
06-23 13:13:09.579: ERROR/InetAddress(7719): InetAddress_getaddrinfo --

please check it.
 

xalion

Member
Licensed User
Longtime User
I don't know how to get stack trace.
and I get follow log:
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): FATAL EXCEPTION: main
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): java.lang.RuntimeException: Unable to create service cn.xasyu.httputilsservice: java.lang.RuntimeException: java.lang.NullPointerException
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3224)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.app.ActivityThread.access$3300(ActivityThread.java:140)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2260)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.os.Looper.loop(Looper.java:143)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.app.ActivityThread.main(ActivityThread.java:5135)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at dalvik.system.NativeStart.main(Native Method)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): Caused by: java.lang.RuntimeException: java.lang.NullPointerException
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at cn.xasyu.main.initializeProcessGlobals(main.java:368)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at cn.xasyu.httputilsservice.onCreate(httputilsservice.java:27)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at android.app.ActivityThread.handleCreateService(ActivityThread.java:3210)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): ... 10 more
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): Caused by: java.lang.NullPointerException
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at anywheresoftware.b4a.objects.streams.File.getDirInternalCache(File.java:55)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at cn.xasyu.httputilsservice._process_globals(httputilsservice.java:138)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): at cn.xasyu.main.initializeProcessGlobals(main.java:365)
06-24 09:41:39.406: ERROR/AndroidRuntime(12826): ... 12 more
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is related to calling File.DirInternalCache from Sub Process_Globals. This issue will be fixed in the next version.
For now change HttpUtilsService with the following change:
B4X:
Sub Process_Globals
    Dim hc As HttpClient
    Dim task As Int
    Dim countWorking As Int
    Dim finishTasks As Int
    Dim maxTasks As Int
    maxTasks = 10
    Dim taskToRequest As Map
    Dim TempFolder As String
    'TempFolder = File.DirInternalCache <-comment this line
    Dim Post As Boolean
    Dim PostBytes() As Byte
    Dim PostInputStream As InputStream
    Dim PostLength As Int
End Sub
Sub Service_Create
    If TempFolder = "" Then TempFolder = File.DirInternalCache '<-- Add this line
    hc.Initialize("hc")
End Sub
 

xalion

Member
Licensed User
Longtime User
fix as your code,but still force close:
06-24 15:07:24.472: ERROR/B4A(15039): httputilsservice_service_start (B4A line: 27)
06-24 15:07:24.472: ERROR/B4A(15039): Do While task < HttpUtils.Tasks.Size
06-24 15:07:24.472: ERROR/B4A(15039): java.lang.RuntimeException: Object should first be initialized (List).
06-24 15:07:24.472: ERROR/B4A(15039): at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:45)
06-24 15:07:24.472: ERROR/B4A(15039): at anywheresoftware.b4a.objects.collections.List.getSize(List.java:118)
06-24 15:07:24.472: ERROR/B4A(15039): at cn.xasyu.httputilsservice._service_start(httputilsservice.java:257)
06-24 15:07:24.472: ERROR/B4A(15039): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 15:07:24.472: ERROR/B4A(15039): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 15:07:24.472: ERROR/B4A(15039): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:104)
06-24 15:07:24.472: ERROR/B4A(15039): at anywheresoftware.b4a.BA.raiseEvent(BA.java:88)
06-24 15:07:24.472: ERROR/B4A(15039): at cn.xasyu.httputilsservice.handleStart(httputilsservice.java:49)
06-24 15:07:24.472: ERROR/B4A(15039): at cn.xasyu.httputilsservice.onStartCommand(httputilsservice.java:44)
06-24 15:07:24.472: ERROR/B4A(15039): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3344)
06-24 15:07:24.472: ERROR/B4A(15039): at android.app.ActivityThread.access$3600(ActivityThread.java:140)
06-24 15:07:24.472: ERROR/B4A(15039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2269)
06-24 15:07:24.472: ERROR/B4A(15039): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 15:07:24.472: ERROR/B4A(15039): at android.os.Looper.loop(Looper.java:143)
06-24 15:07:24.472: ERROR/B4A(15039): at android.app.ActivityThread.main(ActivityThread.java:5135)
06-24 15:07:24.472: ERROR/B4A(15039): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 15:07:24.472: ERROR/B4A(15039): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 15:07:24.472: ERROR/B4A(15039): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-24 15:07:24.472: ERROR/B4A(15039): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-24 15:07:24.472: ERROR/B4A(15039): at dalvik.system.NativeStart.main(Native Method)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): FATAL EXCEPTION: main
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): java.lang.RuntimeException: Unable to start service cn.xasyu.httputilsservice@479e1d20 with null: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (List).
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3358)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.app.ActivityThread.access$3600(ActivityThread.java:140)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2269)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.os.Handler.dispatchMessage(Handler.java:99)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.os.Looper.loop(Looper.java:143)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.app.ActivityThread.main(ActivityThread.java:5135)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at dalvik.system.NativeStart.main(Native Method)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): Caused by: java.lang.RuntimeException: java.lang.RuntimeException: Object should first be initialized (List).
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:144)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at anywheresoftware.b4a.BA.raiseEvent(BA.java:88)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at cn.xasyu.httputilsservice.handleStart(httputilsservice.java:49)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at cn.xasyu.httputilsservice.onStartCommand(httputilsservice.java:44)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3344)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): ... 10 more
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): Caused by: java.lang.RuntimeException: Object should first be initialized (List).
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:45)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at anywheresoftware.b4a.objects.collections.List.getSize(List.java:118)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at cn.xasyu.httputilsservice._service_start(httputilsservice.java:257)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at java.lang.reflect.Method.invokeNative(Native Method)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at java.lang.reflect.Method.invoke(Method.java:521)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): at anywheresoftware.b4a.BA.raiseEvent2(BA.java:104)
06-24 15:07:24.482: ERROR/AndroidRuntime(15039): ... 14 more
 

xalion

Member
Licensed User
Longtime User
It only occured when I power off and power on.
my htc incrible S use quick power off mode.
when I use reboot (swipe all cache), it don't occur.
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Replace in httputilservice

B4X:
link = HttpUtils.Tasks.Get(task)

With

B4X:
link = HttpUtils.Tasks.Get(task)
   link=link.Replace(" ", "%20")
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…