Android Question SQLiteCantOpenDatabaseException

wimpie3

Well-Known Member
Licensed User
I'm currently testing an app on several devices.

One of them, an older HTC, crashes with the following error:
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file

This happens in a module on this line:
B4X:
SQL.Initialize(File.DirDefaultExternal, "mydb.db", True)
Since the "true" flag is passed, a new db should be created, but for one reason or another this does not seem to work on this specific device.

What am I missing?
 

wimpie3

Well-Known Member
Licensed User
Uhmmm... so why would it work on other machines and not on my HTC?

Plus, this is what Erel wrote before:

File.DirRootExternal and File.DirDefaultExternal have a special side effect of adding the STORAGE permission to your manifest file.
 

Pendrush

Well-Known Member
Licensed User
B4X:
If File.ExternalWritable = True Then
    SQL.Initialize(File.DirDefaultExternal, "mydb.db", True)
Else     
    SQL.Initialize(File.DirInternal, "mydb.db", True)
End If
 

Pendrush

Well-Known Member
Licensed User
Or you can use this code:
B4X:
SQL.Initialize(DataBasePath, "mydb.db", True)

Sub DataBasePath As String
   If File.ExternalWritable = True Then
     Return File.DirDefaultExternal  
   Else
     Return File.DirInternal
   End If
End Sub
 

wimpie3

Well-Known Member
Licensed User
This seems to have done the trick... can't I use DirInternal on all occasions and simply leave out the if/then/else?
 
Top