Android Question Strange Error

Marcos Alves

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    Log("starting")

    If File.Exists(File.DirInternal,"dddNorm.db") = False Then
        File.Copy(File.DirAssets,"dddNorm.db",File.DirInternal,"dddNorm.db")
    End If
    
    Sql1.Initialize(File.DirInternal,"golunch.db",True)
Recently when I cleaned the internal storage of one of my apps, I'm getting the error:

android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database

I tried to intercept the running flow but even when I put a break point in the first line of Service_Create on Starter service the error still occurs. I initialize a database there (as the follows code shows), but the code appears that isn't arriving there. I really don't know anymore how to debug as I can't intercept the error (doesn't matter if I put the break point on the first line of starter running in debug mode, the error still occurs ) . What is happening ?? Please , anybody can help me?
 

JohnC

Expert
Licensed User
Longtime User
The first thing I would try is uninstalling the app, then reinstalling it to see if it starts working.

My thinking is that when you did the "Clear Data", you deleted the database - but your app was still running (because Erel takes great efforts to keep the starter service running). Because your app was still running, it wont run the above code again, and that's why it didn't re-install the database again and that's why the other part of your app was not able to open the database.
 
Last edited:
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
The first thing I would try is uninstalling the app, then reinstalling it to see if it starts working.

My thinking is that when you did the "Clear Data", you deleted the database - but your app was still running. Because you app was still running, it wont run the above code again, and that's why it won't re-install the database again and that's why the other part of your app can open the database.
Thanks @JohnC !!! I just found now: I did a mistake and put a Sql1.Initialize(File.DirInternal,"golunch.db",True) IN the segment Process_Globals in a Activity Module (where should only to exist variables and objects declarations). The app code is VERY big (more than 40 modules) and sometime I distracted and made this mistake. The great problem is: when you do this, the app crashes without any log!!!! It isn't possible to find out where is the error (I didn't know that and I've been working with B4A the last 10 years!).
Anyway, register to the forum if anybody has a similar problem.

Thanks again!
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
And I just realized something...

Your code creates/copies a database named "dddNorm.db" from Assets. But then the init code tries to init a database called "golunch.db". That would definitely cause a problem ;)
 
Upvote 0

Marcos Alves

Well-Known Member
Licensed User
Longtime User
And I just realized something...

Your code creates/copies a database named "dddNorm.db" from Assets. But then the init code tries to init a database called "golunch.db". That would definitely cause a problem ;)
The code uses two databases. The dddNorm.db is a static db that the app will use only for select queries to normalize local phone numbers using the city name. The golunch.db is the real app dynamic db that is used to store data, and is created in the start if it's the first time that app initializes (and it doesn't exist yet - look that in initialize clause for golunch.db you can see true in parameter, meaning that if database doesn't exist it's created then).
These are two completely independent from each other databases and are running fine in app.
Anyway, really thanks for your attention. Your fast feedback is a great example of how much B4X community is vibrant and special !!! šŸ‘ :)
 
Upvote 0
Top