Android Question File not found

dougfir

Member
Newbie trying to learn here.

I took the SQLiteLight3Demo that was in one of the forum posts and wanted to substitute a different SQL database.
All I did was change the SQLDateBaseName to the different db.
The new db is in the Files folder. I do have the RuntimePermissions library checked.

I get the "No such file or directory error":
First few lines (of many) of the log:

** Service (starter) Create ***
Error occurred on line: 52 (Starter)
java.io.FileNotFoundException: /data/user/0/b4a.sqlitelight3/files/virtual_assets/wineratings.db: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:160)

As it shows, the error triggers on line 52:
File.Copy(File.DirAssets, SQLDateBaseName, SQLDataBasePath, SQLDateBaseName)

SQLDateBaseName = "WineRatings.db" (correct), SQLDataBasePath = File.DirInternal.

I assumed the compiler would copy the necessary files to the appropriate directory on the phone as it did with the original sample.

Again, I only changed the name of the db in the Starter Create code to match the db file name.

What can I try?

John
 

dougfir

Member
No permission is needed.

Check the actual file in the Files folder and make sure that its name is all lowercased.
Thanks Erel,

The file is all lowercase and in the Files folder.

My main misunderstanding is if you take any of the many SQL demo projects with some .db file in the Files folder it just works - B4A puts the .db file in the correct folder on the phone.

Now I come along and swap another .db file for the original - still in the Files folder.
The only change I made to the code was to change "SQLDateBaseName = "personsflc.db" to SQLDateBaseName = "mydata.db""

The line generating the error was the copy command:
"File.Copy(File.DirAssets, SQLDateBaseName, SQLDataBasePath, SQLDateBaseName)"
But DirAssets is the Files folder correct?
So, how/why is the different .db file not found?

In a very crude way I can get the demo to work with my data by just modifying the table and fields in the original db file and keeping the original name - silly - but it works.

Thanks
John
 
Upvote 0

dougfir

Member
Solution.

The solution appears to be compiling to Release vs Debug.

No change in code just the above compile and my amended sample works.

The mystery to me is exactly where is DirAssets and DirInternal.
In my previous post I assumed File.DirAssets was referring to the Files folder on my PC where all the project files reside.
I guess now DirAssets refers to some location within the APK on the phone??

Somehow B4A, in debug mode vs release mode, does something different in copying [File] files to the phone.

In release mode the complied code can see the new db file and the prog proceeds normally.

So, next I recompiled as debug and ran the demo again but still with my substitute db and everything worked ok.

Release mode had successfully copied the db to wherever it was supposed to go so the next compile as debug could see the db which was still there since I had not uninstalled the app.

Don't know if the above make sense but the sample now works with a different bd which was the point of this whole exercise.


Thanks

John
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…