rgarnett1955 Active Member Licensed User Longtime User Jun 16, 2020 #1 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. Code: 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: Code: 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: Code: 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
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. Code: 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: Code: 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: Code: 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 Jun 16, 2020 #2 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
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
eps Expert Licensed User Longtime User Jun 16, 2020 #3 Be careful, the names are case sensitive. i.e. your error mentions 'resistancetrainer.sqlite3' and your code has 'resistanceTrainer.sqlite3' Upvote 0
Be careful, the names are case sensitive. i.e. your error mentions 'resistancetrainer.sqlite3' and your code has 'resistanceTrainer.sqlite3'
DonManfred Expert Licensed User Longtime User Jun 16, 2020 #4 Also note that you can not open a Database from the Assets folder (Files). The filenames case is more important here. See anser from @eps Upvote 0
Also note that you can not open a Database from the Assets folder (Files). The filenames case is more important here. See anser from @eps
Erel B4X founder Staff member Licensed User Longtime User Jun 16, 2020 #5 This path is wrong. You should either use File.DirInternal or RuntimePermissions.GetSafeDirDefaultExternal. Upvote 0
This path is wrong. You should either use File.DirInternal or RuntimePermissions.GetSafeDirDefaultExternal.