Android Question Sqlite database table not found

JForge

Member
Licensed User
Longtime User
Hello Everyone! I am writing a small program to run some basic queries against a small SQlite database.

I am using the firefox addon, sqlite manager, to create the database and have had a nicely working program all morning.

I added a table to the database this afternoon and now my program cannot seem to read anything from the database at all!! I have no idea what could be wrong, I tried copying it to a new project and compiling that but to no avail. I have also looked into the manage applications, under settings, to clear cache and the like but its not an option for my app.

Here is my log, any and all help would be very much appreciated,
Regards,
John


B4X:
LogCat connected to: B4A-Bridge: Motorola XT557-A000002CB37B43
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
Connected to B4A-Bridge (Wifi)
Installing file.
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example
** Activity (main) Create, isFirst = true **
main_getdata (B4A line: 63)
Cursor1 = SQL1.ExecQuery(Query)
android.database.sqlite.SQLiteException: no such table: BAR: , while compiling: SELECT NAME, END, DESC FROM BAR WHERE DAY = 'Thursday' AND '17' >= START AND '17' <= END
    at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
    at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:101)
    at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:67)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
    at anywheresoftware.b4a.sql.SQL.ExecQuery2(SQL.java:167)
    at anywheresoftware.b4a.sql.SQL.ExecQuery(SQL.java:155)
    at b4a.example.main._getdata(main.java:325)
    at b4a.example.main._activity_create(main.java:260)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    at b4a.example.main.afterFirstLayout(main.java:89)
    at b4a.example.main.access$100(main.java:16)
    at b4a.example.main$WaitForLayout.run(main.java:74)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3719)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:895)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **
 

JForge

Member
Licensed User
Longtime User
Are you copying the DB to the device?, also, try a different SQLite editor.

Its in the files tab of the IDE, so I believe I am. I also tried making it with SQlite database browser. I get the same thing. any idea of an alternate editor?

EDIT: There is a yellow text at the top of the log that says my database file is not used.

Any ideas of what that could mean?
 
Upvote 0

JForge

Member
Licensed User
Longtime User
After some more investigation, the sdcard/Android/data/package/myApp folder doesn't exist.

So the database file is not being transferred. How can I force it to do that?
 
Upvote 0

JForge

Member
Licensed User
Longtime User
The Files tab is the APK (DirAssets) you have to copy the DB to FileDirDefaultExternal which is the device.
I changed the accesses to the db file to the DirAssets, like you mentioned, and now I get a cannot open database file error.

Do I have to copy the database to the sdcard or can I access it from the internal?
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
You can add a copy of your db to DirAssets using the Files tab of the B4A IDE, "Add files" button

Then, take a look at the DBUtils class that can be found here. You can download the class and add it to your app using Project|Add Existing Module on the IDE menu

DBUtils has a method called CopyDBFromAssets which will copy to your db to your app's installation point whether it is internal or external

Add the following to your Main activity in the Activity_Create sub:

B4X:
    'copy db into working folder if not already there  
    DBUtils.CopyDBFromAssets("your.db")


My apologies if I appear to be underestimating your B4A knowledge but your profile says that you're new...

Hope this helps...
 
Upvote 0

JForge

Member
Licensed User
Longtime User
No not at all, thanks for the advice, I copied it to the external manually, and now it all works.

On an unrelated note, I have a question about a listview on a second activity.

I can't get it to scroll or behave like one does on the main activity. Any ideas there?

Again, thanks NJdude and tunderin
 
Upvote 0

tunderin

Member
Licensed User
Longtime User
You should post your listview question on a new thread, I'll watch for it...
 
Upvote 0
Top