Android Question CallSubdelayed2 + Imagedownloader + 404 not found

ALBRECHT

Active Member
Licensed User
Hello,

Im using that kind of script to download images from a website, with the standard ImageDownloader service :

B4X:
links.Initialize 
links.Put(IvMark, ImgUrl)
CallSubDelayed2(ImageDownloader, "Download", links)
it works great but unfortunately, some times the image dont always exists and i can not manage the File Not Found response :

B4X:
ResponseError. Reason: Not Found, Response: <!DOCTYPE html P.......

how could i put an empty image instead, before the 404 error appears ?

Thanks for put me on the way
 

Brandsum

Well-Known Member
Licensed User
copy a placeholder image to your project file. Add some code in the download function of imagedownloader class. Add a else part of httpjob if success. In that else part add your code to load placeholder image.
 
Upvote 0

ALBRECHT

Active Member
Licensed User
Yes i had tried that in first time but the pb is that it return always BEFORE a response.error into the log
l
like that :

B4X:
...
ResponseError. Reason: Not Found, Response: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>404 - File or directory not found.</title>
<style type="text/css">
....
</style>
</head>
<body>
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>404 - File or directory not found.</h2>
  <h3>The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.</h3>
 </fieldset></div>
</div>
</body>
</html>
Imgempty instead <= my replacement log

is it a pb or simply an automatical log at debug mode ?

Fyi : My ImageDownloader use a wait for :

B4X:
Sub Download (ImageViewsMap As Map)
    For i = 0 To ImageViewsMap.Size - 1
        tasks.Put(ImageViewsMap.GetKeyAt(i), ImageViewsMap.GetValueAt(i))
        Dim link As String = ImageViewsMap.GetValueAt(i)
        If cache.ContainsKey(link) Then
            Dim iv As ImageView = ImageViewsMap.GetKeyAt(i)
            iv.SetBackgroundImage(cache.Get(link))
        Else If ongoingTasks.ContainsKey(link) = False Then
            ongoingTasks.Put(link, "")
           
            Dim Job As HttpJob
            Job.Initialize(link, Me)
            Job.Download(link)
            Wait For (Job) JobDone(Job As HttpJob)
            ongoingTasks.Remove(Job.JobName)
            If Job.Success Then
                Dim bmp As Bitmap = Job.GetBitmap
                cache.Put(Job.JobName, bmp)
                If tasks.IsInitialized Then
                    For i = 0 To tasks.Size - 1
                        Dim link As String = tasks.GetValueAt(i)
                        If link = Job.JobName Then
                            Dim iv As ImageView = tasks.GetKeyAt(i)
                            iv.SetBackgroundImage(bmp)
                        End If
                    Next
                End If
            Else
                Log("Imgempty instead")
            End If
            Job.Release
        End If
    Next
End Sub
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim bmp As Bitmap
 If Job.Success Then
                bmp  = Job.GetBitmap
Else
 Log("error")
 bmp = DummyBitmap
 End If
cache.Put(Job.JobName, bmp)
 If tasks.IsInitialized Then
     For i = 0 To tasks.Size - 1
          Dim link As String = tasks.GetValueAt(i)
              If link = Job.JobName Then
          Dim iv As ImageView = tasks.GetKeyAt(i)
         iv.SetBackgroundImage(bmp)
        End If
     Next
  End If
 
Upvote 0

ALBRECHT

Active Member
Licensed User
I understand Erel,

but my question is simply about the :
ResponseError Lines into the log that appears BEFORE your line

B4X:
Log("error")

B4X:
ResponseError. Reason: Not Found, Response: <!DOCTYPE html PUBLIC ......

is it only in Debug Mode ?

Thanks
 
Upvote 0

ALBRECHT

Active Member
Licensed User
So no pbs to compile with that ?
 
Upvote 0
Top