Android Question B4A sqLite DB not loading

rgarnett1955

Active Member
Licensed User
Longtime User
Hi,

I am trying to implement a small sqLite db on my Android Phone. I have created the DB in sqLite Studio and populated it with some look-up tables.

I have added to the files tab. I am using DBUtils 2.02 to do the database copying, but I am getting the following error when I run it.

B4A_sqLiteDB.png


Error Code Cannot find Directory:
Logger connected to:  OPPO CPH1701
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 54 (DBUtils)
java.io.FileNotFoundException: /data/user/0/b4a.rTrainer/files/virtual_assets/resistancetrainer.sqlite3: open failed: ENOENT (No such file or directory)
    at libcore.io.IoBridge.open(IoBridge.java:452)
    at java.io.FileInputStream.<init>(FileInputStream.java:76)
    at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:204)
    at anywheresoftware.b4a.objects.streams.File.Copy(File.java:340)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:777)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:354)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.rTrainer.main.afterFirstLayout(main.java:105)
    at b4a.rTrainer.main.access$000(main.java:17)
    at b4a.rTrainer.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:179)
    at android.app.ActivityThread.main(ActivityThread.java:5730)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:681)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
    at libcore.io.Posix.open(Native Method)
    at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
    at libcore.io.IoBridge.open(IoBridge.java:438)
    ... 19 more

At the point of entering the File.Copy statement:

DB Utils CopyDBFromAssets:
Public Sub CopyDBFromAssets (FileName As String) As String
    Dim TargetDir As String = GetDBFolder
    If File.Exists(TargetDir, FileName) = False Then
        File.Copy(File.DirAssets, FileName, TargetDir, FileName)
    End If
    Return TargetDir
End Sub

The parameters are:
Parameters on entry to File Copy statement:
FileDirAssets     = "AssetsDir"
FileName         = "resistanceTrainer.sqlite3"
TargetDir        = "/storage/emulated/0/Android/data/b4a.rTrainer/files"

I used the pretty much the same code on an app I did back in 2017.

My phone is Build Version 6.0.1

API Level 23.

My phone has an SD card, but I would rather the DB be installed on the phone internal memory as the DB isn't going to be particularly large and will not have any critical data in it.

Best regards
Rob
 

rgarnett1955

Active Member
Licensed User
Longtime User
Additional:

If I manually copy the db to:

"This PC\OPPO CPH1701\Internal storage\Android\data\b4a.rTrainer\files"

It works fine.

Best regards

Rob
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Be careful, the names are case sensitive.

i.e. your error mentions 'resistancetrainer.sqlite3'

and your code has 'resistanceTrainer.sqlite3'
 
Upvote 0
Top