SQLite error: java.lang.IllegalArgumentException: column '_id' does not exist -
help me please, deal mistake.
this logcat:
01-31 15:20:34.768: w/dalvikvm(2166): threadid=1: thread exiting uncaught exception (group=0x40a13300) 01-31 15:20:34.878: e/androidruntime(2166): fatal exception: main 01-31 15:20:34.878: e/androidruntime(2166): java.lang.illegalargumentexception: column '_id' not exist 01-31 15:20:34.878: e/androidruntime(2166): @ android.database.abstractcursor.getcolumnindexorthrow(abstractcursor.java:302) 01-31 15:20:34.878: e/androidruntime(2166): @ android.widget.cursoradapter.swapcursor(cursoradapter.java:338) 01-31 15:20:34.878: e/androidruntime(2166): @ android.widget.simplecursoradapter.swapcursor(simplecursoradapter.java:346) 01-31 15:20:34.878: e/androidruntime(2166): @ ru.zloyel.manager_sutochnoy_arendy_1.kvartitymain.onloadfinished(kvartitymain.java:178) 01-31 15:20:34.878: e/androidruntime(2166): @ ru.zloyel.manager_sutochnoy_arendy_1.kvartitymain.onloadfinished(kvartitymain.java:1) 01-31 15:20:34.878: e/androidruntime(2166): @ android.app.loadermanagerimpl$loaderinfo.callonloadfinished(loadermanager.java:482) 01-31 15:20:34.878: e/androidruntime(2166): @ android.app.loadermanagerimpl$loaderinfo.onloadcomplete(loadermanager.java:450) 01-31 15:20:34.878: e/androidruntime(2166): @ android.content.loader.deliverresult(loader.java:143) 01-31 15:20:34.878: e/androidruntime(2166): @ android.content.cursorloader.deliverresult(cursorloader.java:113) 01-31 15:20:34.878: e/androidruntime(2166): @ android.content.cursorloader.deliverresult(cursorloader.java:43) 01-31 15:20:34.878: e/androidruntime(2166): @ android.content.asynctaskloader.dispatchonloadcomplete(asynctaskloader.java:254) 01-31 15:20:34.878: e/androidruntime(2166): @ android.content.asynctaskloader$loadtask.onpostexecute(asynctaskloader.java:91) 01-31 15:20:34.878: e/androidruntime(2166): @ android.os.asynctask.finish(asynctask.java:631) 01-31 15:20:34.878: e/androidruntime(2166): @ android.os.asynctask.access$600(asynctask.java:177) 01-31 15:20:34.878: e/androidruntime(2166): @ android.os.asynctask$internalhandler.handlemessage(asynctask.java:644) 01-31 15:20:34.878: e/androidruntime(2166): @ android.os.handler.dispatchmessage(handler.java:99) 01-31 15:20:34.878: e/androidruntime(2166): @ android.os.looper.loop(looper.java:137) 01-31 15:20:34.878: e/androidruntime(2166): @ android.app.activitythread.main(activitythread.java:4745) 01-31 15:20:34.878: e/androidruntime(2166): @ java.lang.reflect.method.invokenative(native method) 01-31 15:20:34.878: e/androidruntime(2166): @ java.lang.reflect.method.invoke(method.java:511) 01-31 15:20:34.878: e/androidruntime(2166): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:786) 01-31 15:20:34.878: e/androidruntime(2166): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 01-31 15:20:34.878: e/androidruntime(2166): @ dalvik.system.nativestart.main(native method)
the error appears after clicking on button on main screen appears on second list , application crashes.
my class db.java:
private static final string sql_create_entries = "create table " + table_name + " (" + kvartdb._id + " integer primary key autoincrement, " + name_column + " text not null, " + city_column + " text not null, " + street_column + " text not null, " + home_column + " integer, " + kvartira_column + " integer, " + price_column + " integer " + ");";
kvartiramain.java
import android.app.listactivity; import android.app.loadermanager.loadercallbacks; import android.content.context; import android.content.cursorloader; import android.content.intent; import android.content.loader; import android.database.cursor; import android.os.bundle; import android.view.contextmenu; import android.view.contextmenu.contextmenuinfo; import android.view.menu; import android.view.menuitem; import android.view.view; import android.widget.adapterview.adaptercontextmenuinfo; import android.widget.listview; import android.widget.simplecursoradapter; public class kvartitymain extends listactivity implements loadercallbacks<cursor> { private kvartdb sqh; private static final int activity_create = 0; private static final int activity_edit = 1; private static final int delete_id = menu.first + 1; private simplecursoradapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.kvartiry_list); this.getlistview().setdividerheight(2); sqh = new kvartdb(this); filldata(); registerforcontextmenu(getlistview()); } @override protected void onresume() { // todo auto-generated method stub super.onresume(); // Первоначальный способ. Тоже работает // cursor cursor = dbhelper.getalltodos(); // adapter.changecursor(cursor); getloadermanager().getloader(0).forceload(); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } // Реакция на выбор меню @override public boolean onmenuitemselected(int featureid, menuitem item) { switch (item.getitemid()) { case r.id.insert: createnewtask(); return true; } return super.onmenuitemselected(featureid, item); } @override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.insert: createnewtask(); return true; } return super.onoptionsitemselected(item); } @override public void oncreatecontextmenu(contextmenu menu, view v, contextmenuinfo menuinfo) { super.oncreatecontextmenu(menu, v, menuinfo); menu.add(0, delete_id, 0, r.string.menu_delete); } @override public boolean oncontextitemselected(menuitem item) { switch (item.getitemid()) { case delete_id: // получаем из пункта контекстного меню данные по пункту списка adaptercontextmenuinfo info = (adaptercontextmenuinfo) item .getmenuinfo(); // извлекаем id записи и удаляем соответствующую запись в БД sqh.deletekvart(info.id); // получаем новый курсор с данными getloadermanager().getloader(0).forceload(); // filldata(); return true; } return super.oncontextitemselected(item); } private void createnewtask() { intent intent = new intent(this, kvartiry.class); startactivityforresult(intent, activity_create); } private void filldata() { // cursor = sqh.getallkvart(); // startmanagingcursor(cursor); // string[] = new string[] { kvartdb.name_column }; int[] = new int[] { r.id.label }; adapter = new simplecursoradapter(this, r.layout.list_row, null, from, to, 0); setlistadapter(adapter); // создаем лоадер для чтения данных getloadermanager().initloader(0, null, this); adapter.notifydatasetinvalidated(); } // // Теперь создадим адаптер массива и установим его для отображения наших // // данных // simplecursoradapter notes = new simplecursoradapter(this, // r.layout.list_row, cursor, from, to); // setlistadapter(notes); // // } @override protected void onlistitemclick(listview l, view v, int position, long id) { super.onlistitemclick(l, v, position, id); intent intent = new intent(this, kvartiry.class); intent.putextra(kvartdb._id, id); // активити вернет результат если будет вызвано с помощью этого метода startactivityforresult(intent, activity_edit); } @override protected void onactivityresult(int requestcode, int resultcode, intent intent) { super.onactivityresult(requestcode, resultcode, intent); if (resultcode == result_ok) { filldata(); } } @override protected void ondestroy() { super.ondestroy(); if (sqh != null) { sqh.close(); } } @override public loader<cursor> oncreateloader(int id, bundle args) { // todo auto-generated method stub return new mycursorloader(this, sqh); } @override public void onloadfinished(loader<cursor> loader, cursor cursor) { // todo auto-generated method stub adapter.swapcursor(cursor); } @override public void onloaderreset(loader<cursor> loader) { // todo auto-generated method stub adapter.swapcursor(null); } static class mycursorloader extends cursorloader { kvartdb db; public mycursorloader(context context, kvartdb db) { super(context); this.db = db; } @override public cursor loadinbackground() { cursor cursor = db.getallkvart(); return cursor; } } }
you're creating simplecursoradapter
null
cursor
. null
cursor
doesn't contain _id
column required cursor adapters.
to fix it, pass in cursor
has _id
in projection columns.
Comments
Post a Comment