android - I can' t access to column that is added afterward by me. What should I do? -
firstly created table :
public void oncreate(sqlitedatabase db) { db.execsql("create table " + "sorular" + " (_id integer primary key auto_increment," + "soruicerik text," + " siklar1 text," + " siklar2 text," + " siklar3 text," + "siklar4 text," + "cevap integer);"); }
and after added datas
after decided add new column table , wrote code:
public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { if(newversion > oldversion){ db.execsql("alter table sorular add column zorluk integer"); } }
i added datas new column manuel
but when want access datas new column, application has stopped unexpectedly. code these:
string sorumetin = okunanlar.getstring(okunanlar.getcolumnindex("soruicerik"));//it's normal string siklar1 = okunanlar.getstring(okunanlar.getcolumnindex("siklar1")); //it's normal string siklar2 = okunanlar.getstring(okunanlar.getcolumnindex("siklar2")); //it's normal string siklar3 = okunanlar.getstring(okunanlar.getcolumnindex("siklar3")); //it's normal string siklar4 = okunanlar.getstring(okunanlar.getcolumnindex("siklar4")); //it's normal int dogrucevap = okunanlar.getint(okunanlar.getcolumnindex("cevap")); //it's normal int zorluk = okunanlar.getint(okunanlar.getcolumnindex("zorluk")); //it has problem
what problem? how solve it?
you should change oncreate
this, new column added:
public void oncreate(sqlitedatabase db) { db.execsql("create table " + "sorular" + " (_id integer primary key auto_increment," + "soruicerik text," + " siklar1 text," + " siklar2 text," + " siklar3 text," + "siklar4 text," + " zorluk integer" + "cevap integer);"); }
table created former sql altered in onupgrade
Comments
Post a Comment