android - SQLiteException : No such column -
sorry if question possibly duplicate.
i've looked other similar questions , answers, since i'm not familiar sql terms, i'm not able find solution trough these answers.
can please check code find what's wrong?
public class dbhelper extends sqliteopenhelper { private static final string database_name = "todolist_db"; private static final string table_todos = "todos"; private static final string todo_title = "todo_title"; private static final string todo_category = "todo_category"; private static final string todo_year = "todo_year"; private static final string todo_month = "todo_month"; private static final string todo_day = "todo_day"; private static final string todo_hour = "todo_hour"; private static final string todo_minute = "todo_minute"; private static final string todo_priority = "todo_priority"; public dbhelper(context context) { // context context , name database_name, no factory, version 1 super(context, database_name, null, 1); } public dbhelper(context context, string name, sqlitedatabase.cursorfactory factory, int version) { super(context, name, factory, version); } //creating table first time @override public void oncreate(sqlitedatabase db) { string sql = "create table " + table_todos + " (" + todo_title + " text, " + todo_category + " text, " + todo_year + " integer , " + todo_month + " text, " + todo_day + " integer, " + todo_hour + " text, " + todo_minute + " text, " + todo_priority + " integer);"; log.d("dbhelper", "sql : " + sql); db.execsql(sql); } //upgrading table in other versions of our program @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("drop table if exist " + table_todos); oncreate(db); } //add new todoobj database public void inserttodo(todoobj todoobj) { //hangi database olduðunu belirt //dadatabase'i yazılabilir yap sqlitedatabase db = this.getwritabledatabase(); //verileri tutması için container olustur. contentvalues values = new contentvalues(); //verileri ekle values.put("todo_title", todoobj.getmtitle()); values.put("todo_category", todoobj.getmcategory()); values.put("todo_year", todoobj.getmyear()); values.put("todo_month", todoobj.getmmonth()); values.put("todo_day", todoobj.getmday()); values.put("todo_hour", todoobj.getmhour()); values.put("todo_minute", todoobj.getmminute()); values.put("todo_priority", todoobj.getmprioritydrawableid()); //yeni satır olustur db.insert(table_todos, null, values); //commit db.close(); } public int deletetodo(string title) { string = "title=?"; sqlitedatabase db = this.getwritabledatabase(); int numberofentriesdeleted = db.delete(database_name, where, new string[]{title}); return numberofentriesdeleted; } public arraylist<todoobj> getalltodos() { // veritabanından gelen sonuçları saklayacağımız liste arraylist<todoobj> todos = new arraylist<todoobj>(); sqlitedatabase db = this.getwritabledatabase(); //cursor methodu basit bir select oluþturmak için idealdir //cursor objesi bize sonuçlar içinde dolaþma olanaðý saðlar cursor cursor = db.query(table_todos, new string[]{"todo_title", "todo_category", "todo_year", "todo_month", "todo_day", "todo_hour", "todo_minute","todo_priority"} , null, null, null, null, null); while (cursor.movetonext()) { todoobj todoobj = new todoobj(); todoobj.setmtitle(cursor.getstring(0)); todoobj.setmcategory(cursor.getstring(1)); todoobj.setmyear(cursor.getint(2)); todoobj.setmmonth(cursor.getstring(3)); todoobj.setmday(cursor.getint(4)); todoobj.setmhour(cursor.getstring(5)); todoobj.setmminute(cursor.getstring(6)); todoobj.setmprioritydrawableid(cursor.getint(7)); todos.add(todoobj); } return todos; } public void deleteall() { sqlitedatabase db = this.getwritabledatabase(); /*db.execsql("delete " + table_todos); db.close();*/ db.delete(table_todos, null, null); db.close(); } public arraylist<todoobj> returnbycategory (string categoryname) { // veritabanından gelen sonuçları saklayacağımız liste arraylist<todoobj> todos = new arraylist<todoobj>(); sqlitedatabase db = this.getwritabledatabase(); //cursor methodu basit bir select oluþturmak için idealdir //cursor objesi bize sonuçlar içinde dolaþma olanaðý saðlar cursor cursor = db.query(table_todos, new string[]{"todo_title", "todo_category", "todo_year", "todo_month", "todo_day", "todo_hour", "todo_minute","todo_priority"} , null, null, null, null, null); while (cursor.movetonext()) { if(cursor.getstring(1).tostring().equalsignorecase(categoryname)){ todoobj todoobj = new todoobj(); todoobj.setmtitle(cursor.getstring(0)); todoobj.setmcategory(cursor.getstring(1)); todoobj.setmyear(cursor.getint(2)); todoobj.setmmonth(cursor.getstring(3)); todoobj.setmday(cursor.getint(4)); todoobj.setmhour(cursor.getstring(5)); todoobj.setmminute(cursor.getstring(6)); todoobj.setmprioritydrawableid(cursor.getint(7)); todos.add(todoobj); } } return todos; } }
wild guess: added (not specified) column after run app once.
unistalling , reinstalling app, solves problem.
Comments
Post a Comment