Android Question Dumb question from newbie regarding SQLite...

Steve Miller

Active Member
Licensed User
Longtime User
Ok, newbie here, so dumb question follows...

Where do I put the SQLite database (CustomerTablet.sqlite) so the app finds it?
I created a folder inside my application folder called SQLite adn have the database there so I know where it is.

I defined the Initialize statement as follows:

SQL1.Initialize(File.DirInternal, "CustomerTablet.sqlite",False)

This throws an exception because it is unable to locate the database:


SQL1.Initialize(File.DirInternal, "CustomerTablet.sqlite",False)

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:804)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:37)
at anywheresoftware.b4a.samples.tabhost.main._activity_create(main.java:310)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.samples.tabhost.main.afterFirstLayout(main.java:98)
at anywheresoftware.b4a.samples.tabhost.main.access$100(main.java:16)
at anywheresoftware.b4a.samples.tabhost.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Create, isFirst = true **


** Activity (main) Create, isFirst = true **

I logged where File.DirInternal maps to and it shows this:

/data/data/anywheresoftware.b4a.samples.tabhost/files

Thanks for anticipated help.
 

Steve Miller

Active Member
Licensed User
Longtime User
No clue what that means, or how to do that.

I have the folder structure on my computer as such:

C:\Projects\Android\TabHost
C:\Projects\Android\TabHost\Files
C:\Projects\Android\TabHost\SQLite (this is where my database is)

Excuse my ignorance, but I have no clue where DirInternal or DireDefaultExternal point to. Developing in Basic4Android is all new to me. I'm a .Net developer and am learning this.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Ok, I would recommend you read the documentation, there are 2 PDFs which pretty much cover all you need to know, you can find the link at the top of the screen under DOCUMENTATION.

DirInternal and DirDefaultExternal are directories in the Android device not your PC.
 
Last edited:
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
I was looking at that, but this is an existing database that I need to use. Not letting the program create it.
I don't see anywhere that it tells me to put my existing SQLite database in a specific folder.
 
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
I must have overlooked it, but there is a thread for using your existing database... Looking at that now.
Thanks.
 
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
I think it's something else causing the initialize to fail, but not sure. I followed the directions in this article, with the exception of creating the class. http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/

I'm getting this error:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

The database is in the files list, so not sure what is causing the problem. I'm still looking...
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
Like I said on my post above, you HAVE to copy the database from your Assets directory to the device, you can read THIS or search for samples.

The "FILES" list is what it will be included with your app (APK) that's the assets directory which is READ ONLY, read the documentation on the link, but I strongly recommend you read the PDFs I also mentioned before.
 
Upvote 0

Steve Miller

Active Member
Licensed User
Longtime User
Ah-ha! that was the key. I didn't understand that the database had to be copied from DirAssets to DirInternal. That did the trick. I did that and was able to initialize and select rows from one of the tables. Awesome!
Thanks for your help!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…