android - Sqlite Gives Error -


i'm trying implement loading data database , put different views.

the log cat returns error, cannot find "_id" column.

can me this?

sqlhelper code:

public class fibosqlhelper extends sqliteopenhelper {      public static final string table_filmdb = "fibofilmtop250";      public static final string column_id = "_id";      private static final string database_name = "fibofilmdb250.sqlite";      private static final int database_version = 1;      public static final string column_title = "title";      public static final string column_rating = "rating";      public static final string column_genre = "genre";      public static final string column_time = "time";      public static final string column_premdate = "premdate";      public static final string column_plot = "plot";      private static final string database_create = "create table "             + table_filmdb + "(" + column_id             + " integer primary key autoincrement, " + column_title             + " text not null " + column_rating + " text not null "             + column_genre + " text not null " + column_time             + " text not null " + column_premdate + " text not null "             + column_plot + " " + "text not null)";      public fibosqlhelper(context context) {         super(context, database_name, null, database_version);     }      @override     public void oncreate(sqlitedatabase db) {         db.execsql(database_create);     }      @override     public void onupgrade(sqlitedatabase db, int oldversion,             int newversion) {         // todo auto-generated method stub         log.w(fibosqlhelper.class.getname(),                 "upgrading database version " + oldversion                         + " " + newversion                         + ", destroy old data");         db.execsql("drop table if exists " + table_filmdb);         oncreate(db);     } } 

sqladaptercode:

public class fibosqladapter {      private sqlitedatabase database;      private fibosqlhelper dbhelper;      private string[] allcolumns = { fibosqlhelper.column_id,             fibosqlhelper.column_title, fibosqlhelper.column_genre,             fibosqlhelper.column_premdate, fibosqlhelper.column_time,             fibosqlhelper.column_plot };      public fibosqladapter(context context) {         dbhelper = new fibosqlhelper(context);     }      public void open() throws sqlexception {         database = dbhelper.getwritabledatabase();     }      public void close() {         dbhelper.close();     }      public list<filmdataentity> getallfilmdata() {         list<filmdataentity> fdatas = new arraylist<filmdataentity>();         cursor cursor = database.query(fibosqlhelper.table_filmdb,                 allcolumns, null, null, null, null, null);         cursor.movetofirst();         while (!cursor.isafterlast()) {             filmdataentity fdata = cursortodata(cursor);             fdatas.add(fdata);             cursor.movetonext();         }         cursor.close();         return fdatas;     }      private filmdataentity cursortodata(cursor cursor) {         filmdataentity fdata = new filmdataentity();         fdata.setid(cursor.getlong(1));         fdata.settitle(cursor.getstring(2));         fdata.setrating(cursor.getstring(6));         fdata.setgenre(cursor.getstring(4));         fdata.setpremdate(cursor.getstring(5));         fdata.setshortcut(cursor.getstring(8));          return fdata;      } } 

dataentity:

public class filmdataentity {      private long id;      private string title;      private string rating;      private string genre;      private string premdate;      private string shortcut;      public string getshortcut() {         return shortcut;     }      public void setshortcut(string shortcut) {         this.shortcut = shortcut;     }      public string getgenre() {         return genre;     }      public void setgenre(string genre) {         this.genre = genre;     }      public string getpremdate() {         return premdate;     }      public void setpremdate(string premdate) {         this.premdate = premdate;     }      public string gettitle() {         return title;     }      public void settitle(string title) {         this.title = title;     }      public string getrating() {         return rating;     }      public void setrating(string rating) {         this.rating = rating;     }      public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     } } 

part main activity:

list<filmdataentity> fe1; sqa = new fibosqladapter(this); sqa.open(); fe1 = sqa.getallfilmdata(); 

your adapter looking column called _id returned database query. can either change primary key _id or alternatively when run select query on db do

"select 'selectcolumns' 'yourprimarykey' _id 'yourtablename'"


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -