Android Question Bug in Debug-Mode ?

Filippo

Expert
Licensed User
Longtime User
Hi,

normally also in debug mode after the IF query the compiler should jump to line 215 because the file "BitmapNotFound.png" exists, but it does not.
I have already run "Tools -> Clean project" several times, unfortunately without success.

In Release-mode the IF query works correctly.

1675427210829.png
 

Chris2

Active Member
Licensed User
Longtime User
File.Exists does not support the File.DirAssets folder.
File.Exists(File.DirAssets, bmp) will always return false.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
File.Exists does not support the File.DirAssets folder.
File.Exists(File.DirAssets, bmp) will always return false.
Unfortunately this is not the case.
Here again an example: here the file is no longer present, nevertheless the file is found.

1675452610529.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1675580439252.png


How can I then check if the file exists?
You should know which files were added to File.DirAssets. You added those files.

If you do need this check then add a text file with the list of files (you can actually generate it during compilation with a custom build action), read this file and use it for this check.
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
option:
Log(FileExistAsset("icon.png"))
B4X:
Public Sub FileExistAsset(FileName As String) As Boolean
    For Each Name As String In File.ListFiles(File.DirAssets)
        If FileName = Name Then Return True
    Next
    Return False  
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
option:

B4X:
Public Sub FileExistAsset(FileName As String) As Boolean
    For Each Name As String In File.ListFiles(File.DirAssets)
        If FileName = Name Then Return True
    Next
    Return False
End Sub
I think that File.ListFiles has the same problem of:
You shouldn't use File.Exists with File.DirAssets. The results will not be consistent.
and anyway:
You should know which files were added to File.DirAssets. You added those files.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
I think that File.ListFiles has the same problem of:

and anyway:
This code is a part of a library.
Since this library can be used in multiple apps, there is a risk of writing something that is not present in "dirAssets" or is written incorrectly.
Since this error is not noticed right away, it must be seen right away in the menu display. Therefore I show a warning icon to make you aware of the error.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This code is a part of a library.
Since this library can be used in multiple apps, there is a risk of writing something that is not present in "dirAssets" or is written incorrectly.
Since this error is not noticed right away, it must be seen right away in the menu display. Therefore I show a warning icon to make you aware of the error.
You could create a b4xlib library and include the necessary files in the Files folder.

It is possible to do a similar thing also in a "classic" B4A-jar library:
https://www.b4x.com/android/forum/threads/embedding-files-in-compiled-libraries.37689/
 
Upvote 0
Top