Android Question CallSubdelayed2 + Imagedownloader + 404 not found

Discussion in 'Android Questions' started by ALBRECHT, Sep 9, 2019.

  1. ALBRECHT

    ALBRECHT Active Member Licensed User

    Hello,

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

    Code:
    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 :

    Code:
    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
     
  2. Brandsum

    Brandsum Active 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.
     
    Erel likes this.
  3. ALBRECHT

    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 :

    Code:
    ...
    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 :

    Code:
    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
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    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
     
  5. ALBRECHT

    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

    Code:
    Log("error")
    Code:
    ResponseError. Reason: Not Found, Response: <!DOCTYPE html PUBLIC ......
    is it only in Debug Mode ?

    Thanks
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    No. It is logged from OkHttpUtils2.
     
  7. ALBRECHT

    ALBRECHT Active Member Licensed User

    So no pbs to compile with that ?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    No.
     
  9. ALBRECHT

    ALBRECHT Active Member Licensed User

    ok thanks
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice