Android Studio: java.lang.RuntimeException: Unable to start activity ComponentInfo...: java.lang.IllegalArgumentException: column '_id' does not exist -


the full error:

e/androidruntime: fatal exception: main                                                process: com.myfavoriteplaces.myfavoriteplaces, pid: 32383                                                java.lang.runtimeexception: unable start activity componentinfo{com.myfavoriteplaces.myfavoriteplaces/com.myfavoriteplaces.myfavoriteplaces.listplaces}: java.lang.illegalargumentexception: column '_id' not exist                                                    @ android.app.activitythread.performlaunchactivity(activitythread.java:2695)                                                    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2769)                                                    @ android.app.activitythread.access$900(activitythread.java:177)                                                    @ android.app.activitythread$h.handlemessage(activitythread.java:1430)                                                    @ android.os.handler.dispatchmessage(handler.java:102)                                                    @ android.os.looper.loop(looper.java:135)                                                    @ android.app.activitythread.main(activitythread.java:5910)                                                    @ java.lang.reflect.method.invoke(native method)                                                    @ java.lang.reflect.method.invoke(method.java:372)                                                    @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1405)                                                    @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1200)                                                 caused by: java.lang.illegalargumentexception: column '_id' not exist                                                    @ android.database.abstractcursor.getcolumnindexorthrow(abstractcursor.java:303)                                                    @ android.widget.cursoradapter.init(cursoradapter.java:172)                                                    @ android.widget.cursoradapter.<init>(cursoradapter.java:149)                                                    @ android.widget.resourcecursoradapter.<init>(resourcecursoradapter.java:91)                                                    @ android.widget.simplecursoradapter.<init>(simplecursoradapter.java:104)                                                    @ com.myfavoriteplaces.myfavoriteplaces.listplaces.displaylistview(listplaces.java:49)                                                    @ com.myfavoriteplaces.myfavoriteplaces.listplaces.oncreate(listplaces.java:35)                                                    @ android.app.activity.performcreate(activity.java:6178)                                                    @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1118)                                                    @ android.app.activitythread.performlaunchactivity(activitythread.java:2648)                                                    @ android.app.activitythread.handlelaunchactivity(activitythread.java:2769)                                                     @ android.app.activitythread.access$900(activitythread.java:177)                                                     @ android.app.activitythread$h.handlemessage(activitythread.java:1430)                                                     @ android.os.handler.dispatchmessage(handler.java:102)                                                     @ android.os.looper.loop(looper.java:135)                                                     @ android.app.activitythread.main(activitythread.java:5910)                                                     @ java.lang.reflect.method.invoke(native method)                                                     @ java.lang.reflect.method.invoke(method.java:372)                                                     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1405)                                                     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1200)  

my code class bd :

package com.myfavoriteplaces.myfavoriteplaces;  public class bd {     private int _id;     private string nom_place;     private string type_place;     private string address_place;     private string description_place;      public bd(int id, string nom, string type, string address, string description){         this._id = id;         this.nom_place = nom;         this.type_place = type;         this.address_place = address;         this.description_place = description;     }      public int getid_place(){ return _id; }      public void setid_place(int id){         this._id = id;     }      public string getnom_place(){         return nom_place;     }      public void setnom_place(string nom){         this.nom_place = nom;     }      public string gettype_place(){         return type_place;     }      public void settype_place(string type){         this.type_place = type;     }      public string getaddress_place(){         return address_place;     }      public void setaddress_place(string address){         this.address_place = address;     }      public string getdescription_place(){         return description_place;     }      public void setdescription_place(string description){         this.description_place = description;     } } 

class bdmanager :

package com.myfavoriteplaces.myfavoriteplaces;  import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase;  public class bdmanager {     private static final string table_name = "places";     public static final string key_id_place = "_id";     public static final string key_nom_place = "nom_place";     public static final string key_type_place = "type_place";     public static final string key_address_place = "address_place";     public static final string key_description_place = "description_place";     public static final string create_table_places = "create table              "+table_name+" " +         " (" +         " "+key_id_place+" integer primary key autoincrement," +         " "+key_nom_place+" text" +         " "+key_type_place+" text" +         " "+key_address_place+" text" +         " "+key_description_place+" text" +         ");";      private mysqlite mabasesqlite;     private sqlitedatabase db;      public bdmanager(context context){         mabasesqlite = mysqlite.getinstance(context);     }      public void open() {         db = mabasesqlite.getwritabledatabase();     }      public void close() {         db.close();     }      public long addplace(bd place){         contentvalues values = new contentvalues();         values.put(key_nom_place, place.getnom_place());         values.put(key_type_place, place.gettype_place());         values.put(key_address_place, place.getaddress_place());         values.put(key_description_place, place.getdescription_place());          return db.insert(table_name,null,values);     }      public int modplace(bd place){         contentvalues values = new contentvalues();         values.put(key_nom_place, place.getnom_place());         values.put(key_type_place, place.gettype_place());         values.put(key_address_place, place.getaddress_place());         values.put(key_description_place, place.getdescription_place());          string = key_id_place+" = ?";         string[] whereargs = {place.getid_place()+""};          return db.update(table_name, values, where, whereargs);     }      public bd getplace(int id){         bd p = new bd(0,"","","","");          cursor c = db.rawquery("select * "+table_name+" "+key_id_place+"="+id, null);         if (c.movetofirst()){             p.setid_place(c.getint(c.getcolumnindex(key_id_place)));             p.setnom_place(c.getstring(c.getcolumnindex(key_nom_place)));             p.settype_place(c.getstring(c.getcolumnindex(key_type_place)));                   p.setaddress_place(c.getstring(c.getcolumnindex(key_address_place)));           p.setdescription_place(c.getstring(c.getcolumnindex(key_description_place)));              c.close();         }         return p;     }      public cursor getplaces(){         return db.rawquery("select * "+table_name, null);     }     } 

i literraly have no idea wrong, spent couple of hours trying fix still crashing. error talk "_id" add , still not working...

and crash when try open page. in page want put name place database listview.

package com.myfavoriteplaces.myfavoriteplaces;  import android.content.intent; import android.database.cursor; import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.snackbar; import android.support.v7.app.appcompatactivity;  import android.support.v7.widget.toolbar; import android.view.view; import android.view.menu; import android.view.menuitem; import android.widget.imagebutton; import android.widget.listview; import android.widget.simplecursoradapter; import android.widget.toast;  public class listplaces extends appcompatactivity {      listview mlistview;     bdmanager sav;     simplecursoradapter dataadapter;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.list_places);          mlistview = (listview) findviewbyid(r.id.affichage_listplace);          sav = new bdmanager(this);         sav.open();         sav.getplaces();          displaylistview();     }      private void displaylistview(){         cursor cursor = sav.getplaces();          string[] columns = new string[]{                 bdmanager.key_nom_place         };          int[] = new int[] {                 r.id.nomplace         };          dataadapter = new simplecursoradapter(                 this, r.layout.list_places,                 cursor,                 columns,                 to,                 0         );          mlistview = (listview) findviewbyid(r.id.affichage_listplace);         mlistview.setadapter(dataadapter);     } } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -