Android Question FileNotFoundException

Declan

Well-Known Member
Licensed User
Longtime User
I am using the following code to select a file using a ListView.
B4X:
Sub lvNovels_ItemClick (Index As Int, Value As Object)
    Dim PDF As String
    PDF = Value
    File.Copy(File.DirRootExternal, "/Books/" & PDF & ".pdf",File.DirInternal, "testbook.pdf" )
    CacheDir = File.Combine(File.DirInternalCache, "images")
    File.MakeDir("", CacheDir)
    OpenFilePDF(File.Combine(File.DirInternal, "testbook.pdf"))
End Sub
If there is no associated file, I get the following error:
java.io.FileNotFoundException: /storage/emulated/0/Books/9780797815506.pdf: open failed: ENOENT (No such file or directory)
How can I "trap" this error to display a Toastmessage that the book is unavailable?
 
Top