Android - SQLite could not read row 0, col -1 error -


i have application populates 11 database tables , fetches data , displays in logcat. application used work until changed primary key autoincrement. change worked fine tables 1 table gave me problem.

here dbadapter, , part generate user database (the 1 that's giving me problem):

//variables user table public static final string table_user = "user"; public static final string user_id = "_id"; public static final string username = "username"; public static final string password = "password"; public static final string l_name = "l_name"; public static final string m_name = "m_name"; public static final string f_name = "f_name"; public static final string office = "office"; public static final string cellphonenumber = "cellphone_number"; public static final string landline = "landline"; public static final string address = "address"; public static final string email = "email";  private static final string database_create_user_table = "create table " + table_user          + "(" + user_id + " integer primary key autoincrement,"          + username + " text not null, "         + password + " text not null, "         + l_name + " text not null, "         + m_name + " text not null, "         + f_name + " text not null, "         + office + " text not null, "         + cellphonenumber + " text not null, "         + landline + " text not null, "         + address + " text not null, "         + email + " text not null);" ; 

of course few lines down, in dbadapter's oncreate method, have this:

        database.execsql(database_create_authorized_personnel_table); 

i have userclass shown below:

public class userclass {  private string _id; private string username; private string password; private string l_name; private string m_name; private string f_name; private string office; private string cellphone_number; private string landline; private string address; private string email;   //constructor - empty public userclass(){  }  //constructor public userclass(string username, string password, string lastname, string middlename, string firstname,                      string office, string cpnumber, string landline, string address, string email){     this.username = username;     this.password = password;     this.l_name = lastname;     this.m_name = middlename;     this.f_name = firstname;     this.office = office;     this.cellphone_number = cpnumber;     this.landline = landline;     this.address = address;     this.email = email;  } 

i have setters , getters after constructors.

i have userdbadapter class, takes care of database queries , data fetching, data access object. adduser(userclass user) method:

//add 1 user public long adduser(userclass user){      contentvalues values = new contentvalues();      values.put(username, user.getusername());     values.put(password, user.getpassword());     values.put(l_name, user.getl_name());     values.put(m_name, user.getm_name());     values.put(f_name, user.getf_name());     values.put(office, user.getoffice());     values.put(cellphonenumber, user.getcellphone_number());     values.put(landline, user.getlandline());     values.put(address, user.getaddress());     values.put(email, user.getemail());      return this.mdb.insert(table_user, null, values); } 

and method gets users along details: //get users public list getallusers() { list contactlist = new arraylist(); // select query string selectquery = "select * " + table_user;

    cursor cursor = mdb.rawquery(selectquery, null);      // looping through rows , adding list     if (cursor.movetofirst()) {         {             userclass user = new userclass();              user.set_id(cursor.getstring(cursor.getcolumnindex(user_id) ) );             user.setusername(cursor.getstring(cursor.getcolumnindex(username) ) );             user.setpassword(cursor.getstring(cursor.getcolumnindex(password) ) );             user.setl_name(cursor.getstring(cursor.getcolumnindex(l_name) ) );             user.setm_name(cursor.getstring(cursor.getcolumnindex(m_name) ) );             user.setf_name(cursor.getstring(cursor.getcolumnindex(f_name) ) );             user.setoffice(cursor.getstring(cursor.getcolumnindex(office) ) );             user.setcellphone_number(cursor.getstring(cursor.getcolumnindex(cellphonenumber) ) );             user.setlandline(cursor.getstring(cursor.getcolumnindex(landline) ) );             user.setaddress(cursor.getstring(cursor.getcolumnindex(address) ) );             user.setemail(cursor.getstring(cursor.getcolumnindex(email) ) );               // adding contact list             contactlist.add(user);         } while (cursor.movetonext());     }      // return contact list     return contactlist; } 

in activity, populating database such , getting data such:

public void initializeuserdb(){     log.d("users", "inserting . . .");      userdb.open();     userdb.adduser(new userclass("user1", "1234", "doe", "smith", "john", "makati",                                      "09123456789", "1234567", "lorem ipsum dolor", "loremipsum@dolor.com"));     userdb.adduser(new userclass("user2", "1234", "smith", "doe", "john", "makati",                                      "cpnumber", "landline", "address", "electronic mail address"));       //check if inputted     log.d("reading: ", "reading users . . .");      list<userclass> users = userdb.getallusers();             (userclass user : users) {         string log = "id: " + user.get_id() + "\n" +                         "username: " + user.getusername() + "\n" +                         "password: " + user.getpassword() + "\n" +                         "last name: " + user.getl_name() + "\n" +                         "middle name: " + user.getm_name() + "\n" +                         "first name: " + user.getf_name() + "\n" +                         "office: " + user.getoffice() + "\n" +                         "cellphone number: " + user.getcellphone_number() + "\n" +                         "landline: " + user.getlandline() + "\n" +                         "address: " + user.getaddress() +"\n" +                         "email: " + user.getemail();             // writing contacts log         log.d("details: ", log);     }     userdb.close(); } 

the data inserted properly, however, when comes getting data, logcat tells me there's problem @ line user.setemail(cursor.getstring(cursor.getcolumnindex(email) ) ); in userdbadapter class.

i think able initialize email column, otherwise i'd error data insertion sequence. if comment out line, user.getemail(); method in activity give me null.

i'm confused problem, initialized table right , inserted values properly, don't understand why not able fetch value properly.

another simple mistake on part, sorry.

in userdbadapter class, line public static final string email = "email"; should be: public static final string email = "email";


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -