android - My acitivty keeps force closing because of this error -


my activity keeps force closing because of class exception

    07-02 01:24:59.244: error/androidruntime(660):  java.lang.runtimeexception: unable start activity componentinfo{com.fttech.collection/com.fttech.collection.book_list}:   java.lang.illegalargumentexception: column '_id' not exist 

thsi class

    public class bookdbhelper{      private static final string database_name = "data";     private static final string database_table = "books";     private static final int database_version = 1;       public static final string key_booktitle = "title";     public static final string key_author = "author";     public static final string key_isbn = "isbn";     public static final string key_rating = "rating";     public static final string key_rowid = "_id";       private databasehelper mdbhelper;     private sqlitedatabase mdb;      private static final string database_create =          " create table " + database_table + " ("         + key_rowid + " integer primary key autoincrement, "         + key_booktitle + " text not null,  "         + key_author + " text not null, "         + key_isbn + " text not null, "         + key_rating + " text not null);";      private final context mctx;      public bookdbhelper(context ctx){         this.mctx = ctx;     }     private static class databasehelper extends sqliteopenhelper{         databasehelper(context context){             super(context, database_name, null, database_version);          }          @override         public void oncreate(sqlitedatabase db) {             db.execsql(database_create);          }          @override         public void onupgrade(sqlitedatabase arg0, int arg1, int arg2) {             // todo auto-generated method stub          }     }           public bookdbhelper open()throws sqlexception{         mdbhelper = new databasehelper(mctx);         mdb = mdbhelper.getwritabledatabase();          return this;     }          public void close(){             mdbhelper.close();          }         public long addbook(string book_name, string author, string isbn, string rating){              contentvalues initialvalues = new contentvalues();             initialvalues.put(key_booktitle, book_name);             initialvalues.put(key_author, author);             initialvalues.put(key_isbn, isbn);             initialvalues.put(key_rating, rating);              return mdb.insert(database_table, null, initialvalues);           }         public boolean deletebook(long rowid){             return mdb.delete(database_table, key_rowid + "=" + rowid, null) > 0;           }         public cursor fetchallbooks(){             return mdb.query(database_table, new string []{key_booktitle, key_author, key_isbn, key_rating, key_rowid}, null, null, null, null, null);         }         public cursor fetchbook(long rowid)throws sqlexception {             cursor mcursor =                  mdb.query(true, database_table, new string[] {key_booktitle, key_author, key_rating, key_isbn, key_rowid}, key_rowid + "=" + rowid, null, null, null, null, null);             if(mcursor != null){                 mcursor.movetofirst();             }             return mcursor;  }         public boolean updatebooks(long rowid, string book_name, string author, string rating, string isbn){             contentvalues args = new  contentvalues();             args.put(key_booktitle, book_name);             args.put(key_author, author);             args.put(key_isbn, isbn);             args.put(key_rating, rating);             return              mdb.update(database_table, args, key_rowid + "=" + rowid, null) >0;              } } 

here second class pulls data sqlbase

public class book_list extends listactivity{          private static final int activity_create = 0;     private static final int activty_edit = 1;      private bookdbhelper mdbhelper;             @override     public void oncreate(bundle savedinstancestate){         super.oncreate(savedinstancestate);         setcontentview(r.layout.book_list);         mdbhelper = new bookdbhelper(this);                  mdbhelper.open();         filldata();         registerforcontextmenu(getlistview());       }      private void filldata() {         cursor bookscursor = mdbhelper.fetchallbooks();         startmanagingcursor(bookscursor);          string [] = new string[]{bookdbhelper.key_booktitle};          int[] = new int[]{r.id.text1};          simplecursoradapter books =              new simplecursoradapter(this, r.layout.book_row, bookscursor, from, to);         setlistadapter(books);      }     @override     protected void onlistitemclick(listview l, view v, int position, long id){         super.onlistitemclick(l, v, position, id);          intent = new intent(this, book_edit.class);         i.putextra(bookdbhelper.key_rowid, id);         startactivityforresult(i, activty_edit);      }     @override     protected void onactivityresult(int requestcode, int resultcode, intent intent){         super.onactivityresult(requestcode, resultcode, intent);         filldata();     }  }     public class book_list extends listactivity{     private static final int activity_create = 0;     private static final int activty_edit = 1;      private bookdbhelper mdbhelper;      @override     public void oncreate(bundle savedinstancestate){         super.oncreate(savedinstancestate);         setcontentview(r.layout.book_list);          mdbhelper = new bookdbhelper(this);         mdbhelper.open();         filldata();         registerforcontextmenu(getlistview());       }      private void filldata() {         cursor bookscursor = mdbhelper.fetchallbooks();         startmanagingcursor(bookscursor);          string [] = new string[]{bookdbhelper.key_booktitle};          int[] = new int[]{r.id.text1};          simplecursoradapter books =              new simplecursoradapter(this, r.layout.book_row, bookscursor, from, to);         setlistadapter(books);      }     @override     protected void onlistitemclick(listview l, view v, int position, long id){         super.onlistitemclick(l, v, position, id);          intent = new intent(this, book_edit.class);         i.putextra(bookdbhelper.key_rowid, id);         startactivityforresult(i, activty_edit);     }     @override     protected void onactivityresult(int requestcode, int resultcode, intent intent){         super.onactivityresult(requestcode, resultcode, intent);         filldata();     }  } 

maybe

public static final string key_rowid = "_id"; 

must lower case

public static final string key_rowid = "_id"; 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -