java - Android SQLite Database Version, changed structure now cannot view DB -
my sqlite database appears entering entries fine cannot pull them view them, everytime load activity app crashes, changing database version throws sql exception , force closes app also.
below class sql handled:
package com.uhi.fatfighter; import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper; public class stats { public static final string key_rowid = "_id"; public static final string key_weight = "weight"; public static final string key_waist = "waist"; public static final string key_chest = "chest"; public static final string key_legs = "legs"; public static final string key_arms = "arms"; private static final string database_name = "statsdb"; private static final string database_table = "personalstats"; private static final int database_version = 3; private dbhelper ffhelper; private final context ffcontext; private sqlitedatabase ffdatabase; private static class dbhelper extends sqliteopenhelper { public dbhelper(context context) { super(context, database_name, null, database_version); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table " + database_table + " (" + key_rowid + " integer primary key autoincrement, " + key_weight + " text not null, " + key_waist + " text not null, " + key_chest + " text not null, " + key_legs + " text not null, " + key_arms + " text not null);"); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop table if exist " + database_table); oncreate(db); } } public stats(context c) { ffcontext = c; } public stats open() throws sqlexception { ffhelper = new dbhelper(ffcontext); ffdatabase = ffhelper.getwritabledatabase(); return this; } public void close() { ffhelper.close(); } public long createentry(string weight, string waist, string chest, string legs, string arms) { contentvalues cv = new contentvalues(); cv.put(key_weight, weight); cv.put(key_waist, waist); cv.put(key_chest, chest); cv.put(key_legs, legs); cv.put(key_arms, arms); return ffdatabase.insert(database_table, null, cv); } public string getdata() { string[] columns = new string[] { key_rowid, key_weight, key_waist, key_chest, key_legs, key_arms }; cursor c = ffdatabase.query(database_table, columns, null, null, null, null, null); string result = ""; int irow = c.getcolumnindex(key_rowid); int iweight = c.getcolumnindex(key_weight); int iwaist = c.getcolumnindex(key_waist); int ichest = c.getcolumnindex(key_chest); int ilegs = c.getcolumnindex(key_legs); int iarms = c.getcolumnindex(key_arms); (c.movetofirst(); !c.isafterlast(); c.movetonext()) { result = result + c.getstring(irow) + " " + c.getstring(iweight) + " " + c.getstring(iwaist) + " " + c.getstring(ichest) + " " + c.getstring(ilegs) + " " + c.getstring(iarms) + "\n"; } return result; } }
and below activity calls sql handling class:
package com.uhi.fatfighter; import android.app.activity; import android.os.bundle; import android.text.textutils; import android.widget.textview; public class dbview extends activity { @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.view_stats); textview tv = (textview) findviewbyid(r.id.tvdbinfo); stats dbinfo = new stats(this); dbinfo.open(); string data = dbinfo.getdata(); dbinfo.close(); if (!textutils.isempty(data)) { tv.settext(data); } } }
as said working fine until added fields
logcat:
05-09 13:44:32.761: e/trace(7576): error opening trace file: no such file or directory (2) 05-09 13:44:32.894: e/inputdispatcher(1294): channel '415d5068 com.uhi.fatfighter/com.uhi.fatfighter.splash (server)' ~ channel unrecoverably broken , disposed! 05-09 13:44:34.964: e/trace(7593): error opening trace file: no such file or directory (2) 05-09 13:44:34.988: e/trace(7598): error opening trace file: no such file or directory (2) 05-09 13:44:54.250: e/androidruntime(7598): fatal exception: main 05-09 13:44:54.250: e/androidruntime(7598): java.lang.runtimeexception: unable start activity componentinfo{com.uhi.fatfighter/com.uhi.fatfighter.dbview}: java.lang.classcastexception: android.widget.textview cannot cast android.view.viewgroup 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activitythread.performlaunchactivity(activitythread.java:2185) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2210) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activitythread.access$600(activitythread.java:142) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activitythread$h.handlemessage(activitythread.java:1208) 05-09 13:44:54.250: e/androidruntime(7598): @ android.os.handler.dispatchmessage(handler.java:99) 05-09 13:44:54.250: e/androidruntime(7598): @ android.os.looper.loop(looper.java:137) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activitythread.main(activitythread.java:4928) 05-09 13:44:54.250: e/androidruntime(7598): @ java.lang.reflect.method.invokenative(native method) 05-09 13:44:54.250: e/androidruntime(7598): @ java.lang.reflect.method.invoke(method.java:511) 05-09 13:44:54.250: e/androidruntime(7598): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:791) 05-09 13:44:54.250: e/androidruntime(7598): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:558) 05-09 13:44:54.250: e/androidruntime(7598): @ dalvik.system.nativestart.main(native method) 05-09 13:44:54.250: e/androidruntime(7598): caused by: java.lang.classcastexception: android.widget.textview cannot cast android.view.viewgroup 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.rinflate(layoutinflater.java:747) 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-09 13:44:54.250: e/androidruntime(7598): @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-09 13:44:54.250: e/androidruntime(7598): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:256) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activity.setcontentview(activity.java:1867) 05-09 13:44:54.250: e/androidruntime(7598): @ com.uhi.fatfighter.dbview.oncreate(dbview.java:16) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activity.performcreate(activity.java:5008) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 05-09 13:44:54.250: e/androidruntime(7598): @ android.app.activitythread.performlaunchactivity(activitythread.java:2139) 05-09 13:44:54.250: e/androidruntime(7598): ... 11 more 05-09 13:44:56.765: e/trace(7630): error opening trace file: no such file or directory (2) 05-09 13:45:10.125: e/trace(7649): error opening trace file: no such file or directory (2) 05-09 13:45:10.433: e/trace(7664): error opening trace file: no such file or directory (2) 05-09 13:45:11.183: e/trace(7678): error opening trace file: no such file or directory (2) 05-09 13:45:12.203: e/trace(7695): error opening trace file: no such file or directory (2) 05-09 13:45:14.187: e/androidruntime(7630): fatal exception: main 05-09 13:45:14.187: e/androidruntime(7630): java.lang.runtimeexception: unable start activity componentinfo{com.uhi.fatfighter/com.uhi.fatfighter.dbview}: java.lang.classcastexception: android.widget.textview cannot cast android.view.viewgroup 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activitythread.performlaunchactivity(activitythread.java:2185) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2210) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activitythread.access$600(activitythread.java:142) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activitythread$h.handlemessage(activitythread.java:1208) 05-09 13:45:14.187: e/androidruntime(7630): @ android.os.handler.dispatchmessage(handler.java:99) 05-09 13:45:14.187: e/androidruntime(7630): @ android.os.looper.loop(looper.java:137) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activitythread.main(activitythread.java:4928) 05-09 13:45:14.187: e/androidruntime(7630): @ java.lang.reflect.method.invokenative(native method) 05-09 13:45:14.187: e/androidruntime(7630): @ java.lang.reflect.method.invoke(method.java:511) 05-09 13:45:14.187: e/androidruntime(7630): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:791) 05-09 13:45:14.187: e/androidruntime(7630): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:558) 05-09 13:45:14.187: e/androidruntime(7630): @ dalvik.system.nativestart.main(native method) 05-09 13:45:14.187: e/androidruntime(7630): caused by: java.lang.classcastexception: android.widget.textview cannot cast android.view.viewgroup 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.rinflate(layoutinflater.java:747) 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-09 13:45:14.187: e/androidruntime(7630): @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-09 13:45:14.187: e/androidruntime(7630): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:256) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activity.setcontentview(activity.java:1867) 05-09 13:45:14.187: e/androidruntime(7630): @ com.uhi.fatfighter.dbview.oncreate(dbview.java:16) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activity.performcreate(activity.java:5008) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 05-09 13:45:14.187: e/androidruntime(7630): @ android.app.activitythread.performlaunchactivity(activitythread.java:2139) 05-09 13:45:14.187: e/androidruntime(7630): ... 11 more 05-09 13:45:18.433: e/trace(7722): error opening trace file: no such file or directory (2) 05-09 13:52:02.109: e/trace(7767): error opening trace file: no such file or directory (2) 05-09 13:52:03.554: e/trace(7781): error opening trace file: no such file or directory (2) 05-09 13:55:06.617: e/trace(7807): error opening trace file: no such file or directory (2) 05-09 13:55:26.808: e/androidruntime(7807): fatal exception: main 05-09 13:55:26.808: e/androidruntime(7807): java.lang.runtimeexception: unable start activity componentinfo{com.uhi.fatfighter/com.uhi.fatfighter.dbview}: java.lang.classcastexception: android.widget.textview cannot cast android.view.viewgroup 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activitythread.performlaunchactivity(activitythread.java:2185) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2210) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activitythread.access$600(activitythread.java:142) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activitythread$h.handlemessage(activitythread.java:1208) 05-09 13:55:26.808: e/androidruntime(7807): @ android.os.handler.dispatchmessage(handler.java:99) 05-09 13:55:26.808: e/androidruntime(7807): @ android.os.looper.loop(looper.java:137) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activitythread.main(activitythread.java:4928) 05-09 13:55:26.808: e/androidruntime(7807): @ java.lang.reflect.method.invokenative(native method) 05-09 13:55:26.808: e/androidruntime(7807): @ java.lang.reflect.method.invoke(method.java:511) 05-09 13:55:26.808: e/androidruntime(7807): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:791) 05-09 13:55:26.808: e/androidruntime(7807): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:558) 05-09 13:55:26.808: e/androidruntime(7807): @ dalvik.system.nativestart.main(native method) 05-09 13:55:26.808: e/androidruntime(7807): caused by: java.lang.classcastexception: android.widget.textview cannot cast android.view.viewgroup 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.rinflate(layoutinflater.java:747) 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.rinflate(layoutinflater.java:749) 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 05-09 13:55:26.808: e/androidruntime(7807): @ android.view.layoutinflater.inflate(layoutinflater.java:352) 05-09 13:55:26.808: e/androidruntime(7807): @ com.android.internal.policy.impl.phonewindow.setcontentview(phonewindow.java:256) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activity.setcontentview(activity.java:1867) 05-09 13:55:26.808: e/androidruntime(7807): @ com.uhi.fatfighter.dbview.oncreate(dbview.java:16) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activity.performcreate(activity.java:5008) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1079) 05-09 13:55:26.808: e/androidruntime(7807): @ android.app.activitythread.performlaunchactivity(activitythread.java:2139) 05-09 13:55:26.808: e/androidruntime(7807): ... 11 more 05-09 13:58:40.242: e/trace(7828): error opening trace file: no such file or directory (2) 05-09 13:58:40.500: e/trace(7841): error opening trace file: no such file or directory (2) 05-09 13:58:40.937: e/photodatabasehelper(7828): query fail: empty cursor: android.database.sqlite.sqlitecursor@415ae7e8 05-09 13:58:40.937: e/widgetprovider(7828): cannot load widget: 5
i can see class having trouble casting textview
drop table if exists
is correct syntax.
Comments
Post a Comment