Android Question How to check #FILENOTFOUND when loading image file?

Discussion in 'Android Questions' started by FERNANDO SILVEIRA, Apr 27, 2018.

  1. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Hello guys,

    I have the following code:
    Code:
    bg = LoadBitmapResize(File.DirAssets, wWordOK & ".jpg", ImageView1.Width, ImageView1.Height, True)
    What happen if the file is missing?
    I'd like to test file existance and if the image is not there, load a default image instead.

    Same doubt (file not found) reading text from a file.

    Regards,
    Fernando
     
  2. Claudio Oliveira

    Claudio Oliveira Active Member Licensed User

    Just check if file exists before trying to access it.
    Code:
    If File.Exists(File.DirAssets, wWordOK & ".jpg"then
       bg = LoadBitmapResize(
    File.DirAssets, wWordOK & ".jpg", ImageView1.Width, ImageView1.Height, True)
    End if
     
    FERNANDO SILVEIRA likes this.
  3. FERNANDO SILVEIRA

    FERNANDO SILVEIRA Active Member Licensed User

    Thanx Claudio,
    That's exactly what I was looking for.
     
    Claudio Oliveira likes this.
  4. KMatle

    KMatle Expert Licensed User

    If you type "File." you'll see all methods the File object has.
     
    Claudio Oliveira likes this.
  5. MaFu

    MaFu Well-Known Member Licensed User

    But why check DirAssets?
    It's filled at compile time, therefore you should know which files it contains.
     
    Erel likes this.
  6. Claudio Oliveira

    Claudio Oliveira Active Member Licensed User

    I guess @FERNANDO SILVEIRA's point here is: how to avoid an error for trying to access a missing file. Not necessarily in assets folder...
     
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