android sqlite can't find table "No Such Table" -
android sqlite can't find table "No Such Table" -
it's headache coz people having trouble.. tried many thing , tired. give code , pray :(
if can solve really thanks!!
startactivity :
this.dhn = datahelper.getdatahelper(this); file directory = new file(environment.getdatadirectory() + file.separator + "data" + file.separator + "ko.tb" + file.separator + "databases"); if(directory.exists()) { } else { directory.mkdirs(); updatedb(); } directory = null; seek { guid = this.dhn.guid(); if(this.dhn.getsettings("dbversion") == null || integer.parseint(this.dhn.getsettings("dbversion")) != version || !this.dhn.istableexists("userinfo")) { updatedb(); } } grab (sqliteexception e) { updatedb(); guid = this.dhn.guid(); } public void updatedb() { this.dhn.close(); seek { inputstream myinput; myinput = getassets().open("kelimedb1.db"); // path created empty db string outfilename = "/data/data/ko.tb/databases/" + "kelimedb1.db"; // open empty db output stream outputstream myoutput = new fileoutputstream(outfilename); // transfer bytes inputfile outputfile byte[] buffer = new byte[1024]; int length; while ((length = myinput.read(buffer)) > 0) { myoutput.write(buffer, 0, length); } // close streams myoutput.flush(); myoutput.close(); myinput.close(); buffer = null; outfilename = null; this.dhn.close(); this.dhn = null; this.dhn = datahelper.getdatahelper(this); } grab (ioexception e1) { // todo auto-generated grab block e1.printstacktrace(); } }
datahelper :
private static datahelper singleton; public static datahelper getdatahelper(context context) { if (singleton == null) { singleton = new datahelper(context); openhelper openhelper = new openhelper(singleton.context); singleton.db = openhelper.getwritabledatabase(); } if(!singleton.db.isopen()){ openhelper openhelper = new openhelper(singleton.context); singleton.db = openhelper.getwritabledatabase(); } singleton.context = context; homecoming singleton; } private datahelper(context context) { this.context = context; } public void close() { if (singleton != null) { singleton.db.close(); singleton.db = null; singleton = null; //this.db.close(); this.db = null; } } public string guid() { string sqlquery = "select value userinfo key = 'guid'"; string guid = null; cursor cursor = this.db.rawquery(sqlquery, null); if (cursor.movetofirst()) { guid = cursor.getstring(0); } cursor.close(); homecoming guid; }
error :
java.lang.runtimeexception: unable start activity componentinfo{ko.tb/ko.tb.startscreen}: android.database.sqlite.sqliteexception: no such table: userinfo: , while compiling: select value userinfo key = 'guid' @ android.app.activitythread.performlaunchactivity(activitythread.java:1659) @ android.app.activitythread.handlelaunchactivity(activitythread.java:1675) @ android.app.activitythread.access$1500(activitythread.java:121) @ android.app.activitythread$h.handlemessage(activitythread.java:943) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:130) @ android.app.activitythread.main(activitythread.java:3701) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:507) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:866) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:624) @ dalvik.system.nativestart.main(native method) caused by: android.database.sqlite.sqliteexception: no such table: userinfo: , while compiling: select value userinfo key = 'guid' @ android.database.sqlite.sqlitecompiledsql.native_compile(native method) @ android.database.sqlite.sqlitecompiledsql.compile(sqlitecompiledsql.java:92) @ android.database.sqlite.sqlitecompiledsql.<init>(sqlitecompiledsql.java:65) @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:83) @ android.database.sqlite.sqlitequery.<init>(sqlitequery.java:49) @ android.database.sqlite.sqlitedirectcursordriver.query(sqlitedirectcursordriver.java:42) @ android.database.sqlite.sqlitedatabase.rawquerywithfactory(sqlitedatabase.java:1364) @ android.database.sqlite.sqlitedatabase.rawquery(sqlitedatabase.java:1332) @ ko.tb.datahelper.guid(datahelper.java:171) @ ko.tb.startscreen.oncreate(startscreen.java:76) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) @ android.app.activitythread.performlaunchactivity(activitythread.java:1623) ... 11 more
you may want check this library out managing database . designed assist developers ship app pre-created db.
android sqlite
Comments
Post a Comment