Path 'AssetsDir" does not exist

mwettach

New Member
Licensed User
Longtime User
With this rather standard code (taken from web examples here)

Dim fd As FileDialog
Dim ret As Int
fd.FastScroll = True
fd.FilePath = File.DirAssets
fd.FileFilter = ".txt"
fd.ChosenName = "5-a1.txt"
ret = fd.Show("Choose a file to load:", "Okay", "Cancel", "", Null)
If ret = -3 OR fd.ChosenName = "" Then
Return
End If
If File.Exists(File.DirAssets, fd.ChosenName) = False Then
Msgbox(fd.ChosenName & " does not exist.", "")
Return
End If

I receive an error

java.lang.RuntimeException: Path 'AssetsDir'does not exist
at ...$FileDialog.loadFileList(InputDialog.java:1758)
at ...$FileDialog.Show(InputDialog.java:1808)

I have already verified that my files have been added to the files tab and that they are present in the .apk in a directory "/assets", together with the screen layout (.bal) file.

When I look at the paths in the File Object, they are set as follows:
File.DirInternal = "/data/data/com.mwettach.voktrainer/files"
File.DirDefaultExternal = "/mnt/sdcard/Android/data/com.mwettach.voktrainer/files"
File.DirAssets = "AssetsDir"
File.DirRootExternal = "/mnt/sdcard/"

The testing device is a 7 inch tablet running Android ICS. I am under the impression that the class variable File.DirAssets is not set correctly, for it does not look like a real path - or am I missing something?
 

mwettach

New Member
Licensed User
Longtime User
Follow up - File.DirDefaultExternal works

The path indicated by File.DirInternal does also seem to exist, but I cannot upload files there (my device is not rooted).

With MyPhoneExplorer, I can see the DefaultExternal path
[/Memory Stick]/Android/data/com.mwettach.voktrainer/files

I have uploaded my files there and can see them and use them in the app.

Thanks for the reply.
 
Last edited:
Upvote 0

mwettach

New Member
Licensed User
Longtime User
File.DirAssets works with ListFiles

Strange that I hadn't found several existing posts before stating that the file dialog does not work with assets.

One alternative that I found in those posts is
B4X:
'Read available files
Dim AllFiles As List
AllFiles.Initialize
AllFiles.AddAll(File.ListFiles(File.DirAssets))
which works as expected.

To enable the user to select one file from the list, my app then opens a custom dialog with a Spinner element. This is actually more convenient in my case (few files, just one dir) than the standard FileDialog, because now the user cannot type the file name and see or change the directory.

Just in case this helps another newbie, here is the code:
B4X:
Dim myDropDown As Spinner
myDropDown.Initialize("myDropDown")

Dim text As String
For I = 0 To AllFiles.Size -1
    text = AllFiles.Get(I)
    If text.IndexOf(".txt") > - 1 Then
        myDropDown.Add(text)
    End If      
Next
   
'Let the user select a file
Dim cd As CustomDialog
cd.AddView(myDropDown, 0, 0, 300, 40)
cd.Show("DropDown Title", "OK", "Cancel", "", Null)
text = myDropDown.SelectedItem
 
Upvote 0
Top