Android Question Emulator and SQLite

jimmyF

Active Member
Licensed User
Longtime User
Is there a trick to getting SQLite working in the emulator or is it not supported?

I get this error:

*** Service (starter) Create ***
Error occurred on line: 13 (KeyValueStore)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44)
at bz.sef.TagItNotesB4.keyvaluestore._initialize(keyvaluestore.java:94)
at bz.sef.TagItNotesB4.starter._service_create(starter.java:190)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at bz.sef.TagItNotesB4.starter.onCreate(starter.java:55)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3191)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
** Service (starter) Start **
 

Star-Dust

Expert
Licensed User
Longtime User
There seems to be an error in the code. The file is not accessible. Enter the part of the code where you access the DataBase.

You are not trying to access the DataBase location in the File.DirAssets folder, right?
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
False alarm! :oops:
Found it myself.
I used the File.DirDefaultExternal for the KeyValueStore.
This folder is not accessible in the emulator, I believe.
Should have been File.DirInternal
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
I most probably have! :D
And where would I find the instructions on how to do so?
I don't see an option in the b4J app.
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
Tried it again with a new emulator I have just created.

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.
    Dim folder As String
    If File.ExternalWritable Then
        folder = File.DirDefaultExternal 
    Else 
        folder = File.DirInternal
    End If
   
    kvs.Initialize(folder,"DataStore")

And this is the error:

*** Service (starter) Create ***
Error occurred on line: 13 (KeyValueStore)
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:696)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:671)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:44)
at bz.sef.TagItNotesB4.keyvaluestore._initialize(keyvaluestore.java:94)
at bz.sef.TagItNotesB4.starter._service_create(starter.java:190)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at bz.sef.TagItNotesB4.starter.onCreate(starter.java:55)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3162)
at android.app.ActivityThread.-wrap5(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1550)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
** Service (starter) Start **

What am I doing wrong?
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="24"/>
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
That's it! :D
Thank you so much!
 
Upvote 0
Top