Android Question Failure on copying external SQLite database to phone

Bernard Harris

Member
Licensed User
I am trying to use the below code to get an externally created SQLite database (created with DB Browser) onto a phone. I've seen another thread concerning this but none of the tips have helped me.

If File.Exists(File.DirInternal, "Inventory.db") = False Then
File.Copy(File.DirAssets, "Inventory.db", File.DirInternal, "Inventory.db")
End If

The error I receive is: java.io.FileNotFoundException: /data/user/0/b4a.example/files/virtual_assets/inventory.db: open failed: ENOENT (No such file or directory)

I've selected the database and added it to my Default Group. I also added to the project Manifest android:name="android.permission.WRITE_EXTERNAL_STORAGE".

Is it failing on the Windows side or on the Android side? How else can I get the database to the device if this doesn't work?

Thanks in advance!
 

Mahares

Expert
Licensed User
Longtime User
The error I receive is: java.io.FileNotFoundException: /data/user/0/b4a.example/files/virtual_assets/inventory.db: open failed: ENOENT (No such file or directory)
1. Remove the permission statement from manifest. No need for permission.
2. The database needs to be added to the assets folder by clicking on the 'Add Files' button in the IDE files tab. Look for the file on your PC, then click it when you find it and then click 'open to put it properly in the assets folder.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I did do that, just forgot to mention it. And it copied the database file to the directory also.
B4X:
If File.Exists(File.DirInternal, "inventory.db") = False Then
        file.Copy(File.DirAssets, "inventory.db", File.DirInternal, "inventory.db")
End If
Try to change the code to lower case for inventory.db instead of Inventory.db.That might be it. If you want to export your project so members can check it out. The problem could be somewhere else.
 
Upvote 0

Bernard Harris

Member
Licensed User
Thanks for your quick response by the way!

So I changed it to lower case and then put a break point on this code. This code is in the Starter Service_Create Sub and it's the first thing executed. It did not find the file existing on the phone so it then executed the Copy statement. Then it failed immediately with the error: java.io.FileNotFoundException: /data/user/0/b4a.example/files/virtual_assets/inventory.db: open failed: ENOENT (No such file or directory)

One question I have on this is - why is it looking in this particular folder, that's not the folder in Windows? Is this the folder on the Windows side, the Android side, or the package itself that it built in Windows?

Another note on this: I am able to successfully create the table myself and insert test rows within the same Sub but now I want to pull my actual data in and having this difficulty.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
If you want to export your project so members can check it out, that is great. I don't think it is a big problem.
 
Upvote 0

Bernard Harris

Member
Licensed User
Here is my project. I haven't built one for a couple years now so it might be rough but nothing too out of the ordinary.
 

Attachments

  • Foodstuff.zip
    19.4 KB · Views: 133
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It worked for me. I did not do anything Here is a screen shot of the first page. Try to uninstall the app and install it all over
 

Attachments

  • Bernard.png
    Bernard.png
    104.1 KB · Views: 144
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It worked when I uninstalled from the phone and then rebuilt it.
That's good. It is a very good project by the way, although I did not dive too much into it. Nothing to be ashemed of. You might want to start working with B4XPages project. as Erel always advises these days.
You may want to change:
B4X:
p.SetLayoutAnimated(100, 0, 0, 100%x, 50dip)
to this, you will get the attached look:
B4X:
p.SetLayoutAnimated(100, 0, 0, 100%x, 100dip)
'
 

Attachments

  • Bernard2.png
    Bernard2.png
    76.8 KB · Views: 124
Upvote 0

Bernard Harris

Member
Licensed User
Thank you! I have been programming now for 38 years and built only one Android program using B4A a couple years ago. It is a Load Delivery app for the company I work at. It's doing well even though it's outdated. I enjoy the Basic language the most because it's truly a RAD environment.

Thanks again for the quick response and your help, I appreciate it greatly! :)
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I suppose that the problem was the Package name B4A Example.
When you develop a program or even when you download programs from the forum always change the Package name and the Application Label as described in the B4X Getting started booklet.
 
Upvote 0
Top