HttpUtils: error loading image

priitp

Member
Licensed User
Longtime User
Hi.

Using HttpUtils.DownloadList and HttpUtils.IsSuccess reports as this is image downloaded OK

In reality got an error:

Completed HttpJob=(ArrayList) [1290684, 1290683, 1290685, 1290680, 1290677, 1290678, 1290681, 1290653, 1290657, 1290652, 1290654, 1290630, 1290628, 1290629, 1290493, 1290631, 1290618, 1290608, 1290658, 1290623]
httputils_getbitmap (B4A line: 96)
b = LoadBitmap(HttpUtilsService.TempFolder, SuccessfulUrls.Get(URL))

java.lang.RuntimeException: Error loading bitmap.
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:500)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:491)
at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:911)
at stuudio.uudishimu.httputils._getbitmap(httputils.java:102)
at stuudio.uudishimu.main._jobdone(main.java:992)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:772)
at anywheresoftware.b4a.keywords.Common.CallSub2(Common.java:759)
at stuudio.uudishimu.httputilsservice._processnexttask(httputilsservice.java:241)
at stuudio.uudishimu.httputilsservice._response_streamfinish(httputilsservice.java:342)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA$2.run(BA.java:244)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Error loading bitmap.


HTTP Utils error: java.lang.RuntimeException: Error loading bitmap. Url:http://f.elu24.ee/f/2012/04/17/1060050t12h4953.jpg

Here you see the problematic link to the image. IE9 loads the image OK BTW.
To overcome the problem I modified Http Utile a bit but for sure this is not the perfect way.

B4X:
Sub GetBitmap(URL As String) As Bitmap
   Dim b As Bitmap
   If IsSuccess(URL) = False Then
      Log("Task not completed successfully.")
      b.InitializeMutable(10dip, 10dip)  ' false initialising a bitmap to return something   
      Return b
   End If
   Try   
      b = LoadBitmap(HttpUtilsService.TempFolder, SuccessfulUrls.Get(URL))
   Catch
      Log("HTTP Utils error: " & LastException.Message & " Url:" & URL)
      b.InitializeMutable(10dip, 10dip)   ' false initialising a bitmap to return something

   End Try
   Return b
End Sub

May be Erel you can look at the case and create more bulletproof solution.

Thanks
Priit

BTW In the future it would be nice to have some kind of job queue built inside HttpUtils. So user could just add jobs to queue at the time the previous job is not finished yet.
 

priitp

Member
Licensed User
Longtime User
No, I haven't.
I think the problem is more general as there are lot of subformats for the graphics and for sure all are not supported.

If the LoadBitmap(HttpUtilsService.TempFolder, SuccessfulUrls.Get(URL)) fails to load the downloaded image then we get error and thread will halt.
May be it would be good to check the LoadBitmap before its is flaged as successfull download.


It is possible that there will appear some image in unknown (sub)format for this method.
Our application just leaves a blank place for the image and for us it's OK.

Priit
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
LoadBitmap and HttpUtils (or Http library) are not related. It is important to understand the source of this problem. I guess that this image is not supported by Android internal decoder.
In that case it is not related to HttpUtils at all.

It is up to the developer to correctly handle the case where an external image fails. This is exactly the purpose of Try.. Catch blocks.
 
Upvote 0

priitp

Member
Licensed User
Longtime User
The LoadBitmap(HttpUtilsService.TempFolder, SuccessfulUrls.Get(URL)) is part of HttpUtils line 97 and the error accours inside HttpUtils.

Yes, we changed the HttpUtils in our project but in my opinion the problem is general and the same can happen to every user.
Having this in mind I suggest to change it in next version of HttpUtils.

Thanks
Priit
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…