Android Question File not found in File.DirAssets

Theuns

Member
Hi all. My first time here - just starting with B4X and am very excited with it. Great work!

I've been struggling with this problem for two full days and cannot find a satisfactory answer. Maybe I'm not asking the right questions?

- My B4A version is 9.80.
- My Phone is Android 9 pie. I've inserted/changed the lines
#CanInstallToExternalStorage: True
#DebuggerForceStandardAssets: true


- and also in the Manifest Editor, I added the targetSdkVersion: <uses-sdk android:minSdkVersion="4" android:targetSdkVersion="28" />

The code shown here under is the start of the example called "Layers". (Horse running across a mountainous background). Files horse00.png , horse01.png ... etc. are all in File Manager under "#Default Group".

When ran with IDE set to Debug, it runs fine, but when I Release the app, it says "FileNotFoundError". See hi-lighted lines. When I examen the Files.DirAssets folder, it contains two entries called "images" and "webkit". Trying to open them as a folder (File.DirAssets/images) , I get "not a folder" error.

B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Layers
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: True
    #DebuggerForceStandardAssets: true
#End Region

'Activity module
Sub Process_Globals
    Dim ProgName As String                    : ProgName = "Layers"
    Dim ProgVersion As String                : ProgVersion = "V 1.0"
    Dim TimerHorse As Timer
    Dim TimerBackground As Timer
    Dim TimerInterval As Long
End Sub

Sub Globals
    Dim ImageI As Int                                ' index of the current horse image
    Dim ImageDir As Int                            ' direction of the horse image
    Dim ImageNumber As Int                    ' number of horse images
        ImageNumber = 8
    Dim imgHorse(2, ImageNumber) As Bitmap        ' array horse image bitmaps
    Dim imvBackground As ImageView    ' background ImageView
    Dim imvForeground As ImageView    ' foreground ImageView
    Dim cvsForeground As Canvas            ' canvas for the foreground image
    Dim rectHorse As Rect                        ' rectangle of the horse image
    Dim HorseWidth As Int                        ' horse image width
    Dim HorseHeight As Int                    ' horse image height
    Dim HorseTop As Int                            ' horse image top
    Dim HorseLeft As Float                    ' current left position of the horse image
    Dim HorseDelta As Float                    ' horse move per timer tick
    Dim BackgroundLeft As Float            ' current left position of the background
    Dim BackgroundDelta As Float        ' background move per timer tick
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim i As Int
    ' load the horse images
    ' first index = 0 for galloping to the right
    ' first index = 1 for galloping to the left
    For i = 0 To ImageNumber - 1
        [B]imgHorse(0, i).Initialize(File.DirAssets, "horse0" & i & ".png")
        imgHorse(1, i).Initialize(File.DirAssets, "horse1" & i & ".png"[/B])
    Next

Please can somebody help?

Regards to all.

Theuns
 

Theuns

Member
I've tried to attach the original File I downloaded from Resources Code sight for the book by Wyken Seagrave, but it is too large to upload. Will try to split somehow.
(Downloaded from https://pennypress.co.uk/wp-content/uploads/2013/04/Layers.zip)

The error I get is on my mobile phone and reads as follows:-
"An error has occurred in sub:main_activity_create(java line: 387) java.io.FileNotFoundException: hors00.png"
Continue?

The log only states: Library 'Reflection' is not used (warning #32)

I inserted "#BridgeLogger: True" , but the logger only says : Logger connected to: ZTE ZTE Blade L130

Theuns
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You must be able to read the logs. Switch to debug mode. If it doesn't help, enable developer tools on your device and make sure that logs are active.

"An error has occurred in sub:main_activity_create(java line: 387) java.io.FileNotFoundException: hors00.png"
Note that it says hors00 instead of horse00.
 
Upvote 0

Theuns

Member
I just miss-typed when I typed the error in the post here.
The error does not occur in Debug mode. It works fine then. It is when I compile in Release mode and run it on my Mobile I get the error on the mobile only.

I will try another small project with a text file and see what happens and will let you know. MY phone uses android 9.0 pie.

Thank you for your help so far.
 
Upvote 0

Theuns

Member
I tried another project with a text-file in File-Manager with content from file in File.DirAssets into Listview. It worked as 100% planned in Debug mode, but bombed in Release mode.

There must be something strange using File.DirAssets?

Also when I write to Log (e.g. Log("Looping to fill Listview") ) does not show in the Log panel?

Regards
 
Upvote 0

Theuns

Member
Upload the project.
I found that the problem was with the way the sd card was formatted on the phone. If formatted as an extented primary memory, it gives these problems. After reformatting my sd card as "removable", the app worked fine in debug and release.

Thank you very much for your time and knowledge.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…