Android Question java.io.FileNotFoundException on File.WriteMap

Frank Cazabon

Member
Licensed User
Longtime User
I have a pretty old app in B4A 5 that runs fine on older Android devices. I am trying to run it now an Android 11 and getting an error:

java.io.FileNotFoundException: /storage/emulated/0/Android/data/MyAppName/files/MyAppName.config: open failed: ENOENT (No such file or directory)

The code is:

B4X:
Dim configMap As Map
        configMap.Initialize
        If File.Exists(ConfigFilePath, ConfigFileName) = False Then
            configMap.Put("SQLUrl", SQLUrl)
            File.WriteMap(ConfigFilePath, ConfigFileName, configMap)
        Else
            configMap = File.ReadMap(ConfigFilePath, ConfigFileName)
            SQLUrl = configMap.Get("SQLUrl")
        End If

The error occurs on File.WriteMap(ConfigFilePath, ConfigFileName, configMap)

I'm not sure if this is a permissions thing or maybe a version thing.

I have copied the old version and have compiled it in the latest version of B4A (12.50) but I still get the error.
 

sirjo66

Well-Known Member
Licensed User
Longtime User
you need to change ConfigFilePath with
B4X:
rp.GetSafeDirDefaultExternal("")
and you need to add
B4X:
Dim rp As RuntimePermissions
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Where is the FULL ERROR? Where is the Full-Code used? I can not see what ConfigFilePath contains
 
Upvote 0

Frank Cazabon

Member
Licensed User
Longtime User
Here's the full error:

Logger connected to: Zebra Technologies TC21
--------- beginning of main
** Activity (main) Create (first time) **
Error occurred on line: 189 (Main)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/MyApp/files/MyApp.config: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileOutputStream.<init>(FileOutputStream.java:236)
at anywheresoftware.b4a.objects.streams.File.OpenOutput(File.java:449)
at anywheresoftware.b4a.objects.streams.File.WriteMap(File.java:291)
at IBC.PackTrack.main._activity_create(main.java:587)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at IBC.PackTrack.main.afterFirstLayout(main.java:105)
at IBC.PackTrack.main.access$000(main.java:17)
at IBC.PackTrack.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7747)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7633)
at libcore.io.IoBridge.open(IoBridge.java:478)
... 20 more
** Activity (main) Resume **
you need to change ConfigFilePath with
B4X:
rp.GetSafeDirDefaultExternal("")
and you need to add
B4X:
Dim rp As RuntimePermissions
Thank you, that seems to have solved it
 
Upvote 0
Top