Issues when using sqlite db copied from assets folder on Android -



Issues when using sqlite db copied from assets folder on Android -

although getting favorable reviews, next errors piling , giving grief:

java.lang.runtimeexception: unable start activity componentinfo{com.svs.missions.missionsgalleryview}: android.database.sqlite.sqliteexception: no such table: missions: , while compiling: select * missions banner not null order title collate nocase @ android.app.activitythread.performlaunchactivity(activitythread.java:2787) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2803) @ android.app.activitythread.access$2300(activitythread.java:135) @ android.app.activitythread$h.handlemessage(activitythread.java:2136) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:144) @ android.app.activitythread.main(activitythread.java:4937) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:521) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) @ dalvik.system.nativestart.main(native method) caused by: android.database.sqlite.sqliteexception: no such table: missions: , while compiling: select * missions banner not null order title collate nocase @ android.database.sqlite.sqlitecompiledsql.native_compile(native method) @ android.database.sqlite.sqlitecompiledsql.compile(sqlitecompiledsql.java:91) @ android.database.sqlite.sqlitecompiledsql.<init>(sqlitecompiledsql.java:64) @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:80) @ android.database.sqlite.sqlitequery.<init>(sqlitequery.java:46) @ android.database.sqlite.sqlitedirectcursordriver.query(sqlitedirectcursordriver.java:53) @ android.database.sqlite.sqlitedatabase.rawquerywithfactory(sqlitedatabase.java:1409) @ android.database.sqlite.sqlitedatabase.querywithfactory(sqlitedatabase.java:1293) @ android.database.sqlite.sqlitedatabase.query(sqlitedatabase.java:1248) @ android.database.sqlite.sqlitedatabase.query(sqlitedatabase.java:1328) ...

it seems not tables created when copying db assets folder. here 1 feedback message user in market panel:

“whenever click on "missions" app forcefulness closes. other links seem ok.”

so nail , miss. users, appears none of tables copied.

i’m tempted rip out database re-create altogether , create db on launch, still cannot guarantee db created (and won't of metadata ships app, unless download on launch, lots of info btw). seems little silly me though. many different platforms support. disjointed.

funny phone call table creation code on every launch sure db tables exist, , doesn’t prepare (snippet here):

this.opendb(); db.execsql("create table if not exists missions (_id integer primary key autoincrement, title text, description text, created text, orghtml text, unique(id) on conflict ignore);"); ... this.closedb();

i found this:

http://www.anddev.org/networking-database-problems-f29/missing-table-in-sqlite-with-specific-version-of-desire-hd-t50364.html

and applying workaround, still getting error reports.

i don’t know sure if on htc devices, next lead of forum post above.

background:

the db in assets folder. 2.8mb large, , assign .mp3 extension avoid compression re-create (fix old issue known).

one thing haven't added yet check free space, next. may create whole db empty if there not plenty free space suppose. if runs out of free space when copying assets folder db, db should corrupted think.

btw: oncreate , onupgrade empty:

@override public void oncreate(sqlitedatabase sqlitedatabase) { } @override public void onupgrade(sqlitedatabase sqlitedatabase, int i, int i1) { }

this works on of our test devices:

htc aria, 2.1, little footprint, 16mb heap

original droid, 2.2.1

samsung galaxy, 2.2

asus tablet (don’t have model), 3.0

xoom, 3.1

the db class extends sqliteopenhelper:

public class dbmanager extends sqliteopenhelper {

here code used (since none of our users have contacted yet, don't know log.e writes are, unfortunately):

... private static final string db_name = "db.mp3"; private static final string db_path = "/data/data/com.svs/databases/"; ... public boolean createnewdatabasefromasset() { file file = new file(db_path , db_name); if (file.exists()) { homecoming true; } sqlitedatabase db_read = null; db_read=this.getreadabledatabase(); db_read.close(); seek { inputstream assetsdb = this.context.getassets().open(db_name); outputstream dbout = new fileoutputstream(db_path + db_name); byte[] buffer = new byte[1024]; int length; while ((length = assetsdb.read(buffer)) > 0) { dbout.write(buffer, 0, length); } dbout.flush(); dbout.close(); assetsdb.close(); this.buildtables(); log.i(tag, "new database created..."); homecoming true; } grab (ioexception e) { log.e(tag, "io error. not create new database..."); e.printstacktrace(); this.buildtables(); homecoming false; } grab (sqliteexception e) { log.e(tag, "database locked. not create new database..."); e.printstacktrace(); this.buildtables(); homecoming false; } } public dbmanager opendb() { if (!createnewdatabasefromasset()) homecoming null; if (db==null){ dbmanager = new dbmanager(context); db = dbmanager.getwritabledatabase(); } homecoming this; }

i thought update reply since it's bit old. on tablets @ least, of android api 19, can have multiple users. accounts on nexus 7 @ to the lowest degree go directory, /data/users/10/

you have next now:

inputstream input = this.context.getassets().open(database_name); file dbfile = context.getdatabasepath(database_name); dbfile.getparentfile().mkdir(); dbfile.createnewfile(); outputstream output = new fileoutputstream(dbfile.getabsolutepath());

so can't assume path app located statically @ /data/data//databases.

android

Comments

Popular posts from this blog

groovy - Grails 2.0 plans for arbitrary .gsp pipelining? -

linux - Why do the 32-bit and 64-bit Compiled Versions of this Program Populate Memory in this Way? -

c# - Code indenting specified at project/solution level rather than global -