B4J Question B4J standalone with sqlite

Phil Thompson

Member
Licensed User
Longtime User
I get this error when trying to compile a stand alone app in B4J
java.lang.RuntimeException: java.io.FileNotFoundException: D:\B4J_Projects\GrimsbyCurling\B4J\Objects\temp\build\bin\TimeClock.db (The system cannot find the file specified)

TimeClock.db is located in the Objects Folder

Both of the options below work fine in debug and release modes.

Option 1
File.Copy(File.DirApp, "TimeClock.db", xui.DefaultFolder, "TimeClock.db")
sql1.InitializeSQLite(xui.DefaultFolder, "TimeClock.db", True)

Option 2
File.Copy(File.DirApp, "TimeClock.db", File.DirData("EventClock"), "TimeClock.db")
sql1.InitializeSQLite(File.DirData("EventClock"), "TimeClock.db", True)
 

LucaMs

Expert
Licensed User
Longtime User
I don't know why the file is not found, since the project works, but most likely you can solve the problem by moving the file from Object to Files and then copying it with:
B4X:
File.Copy(File.DirAssets, "TimeClock.db", xui.DefaultFolder, "TimeClock.db")
 
Upvote 0

Phil Thompson

Member
Licensed User
Longtime User
This works as far as the run time is concerned but creates another problem. TimeClock.db is an interactive db and I cannot update it in DirAssets.

On Exit
File.Copy(xui.DefaultFolder, "TimeClock.db", File.DirApp, "TimeClock.db")
Works fine But the Stand Alone Compile fails.

It appears that the compiler is not copying the file from FileDirApp
 
Upvote 0

Phil Thompson

Member
Licensed User
Longtime User
Do you set the Data Folder?
B4X:
xui.SetDataFolder("xxx")
Yes. The app works just fine in debug and release modes
The standalone compiler appears to not copy the db from DirApp
Why do you need to copy the db on exit? From where to where?
Just want a hot backup of the DB File

Now Working with


xui.SetDataFolder("EventClock")
If File.Exists(xui.DefaultFolder,"TimeClock.db")=False Then
File.Copy(File.DirApp, "TimeClock.db", xui.DefaultFolder, "TimeClock.db")
End If
sql1.InitializeSQLite(xui.DefaultFolder, "TimeClock.db", True)

and on exit
File.Copy(xui.DefaultFolder, "TimeClock.db", File.DirApp, "TimeClock.db")
 
Upvote 0

JohnJ

Member
Licensed User
Longtime User
I had the same issue after creating the exe. I solved this by creating a Files folder and coping my sqlite file into it.
 

Attachments

  • Screenshot 2024-11-02 085103.png
    21.6 KB · Views: 11
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…