database - Failed to read row 0, column 1 from a CursorWindow (Android) -


i have created table players in oncreate() method in mysqlitehelper.java:

string create_players_table = "create table players  (id integer primary key autoincrement, name text, password text, score integer)";  db.execsql(create_players_table); 

and have update method in same class like:

public int playerupdate(player pl) {      // 1. reference writable db     sqlitedatabase db = this.getwritabledatabase();      // 2. create contentvalues add key "column"/value     contentvalues values = new contentvalues();     values.put("name", pl.getname());     values.put("password", pl.getpassword());     values.put("score", pl.getscore());      // 3. updating row     int = db.update(table_players, // table             values, // column/value             key_id + " = ?", // selections             new string[] { string.valueof(pl.getid()) }); // selection args      // 4. close     db.close();      return i; } 

and when call functions change score variable as:

public void scoreup() {     helper.playerupdate(new player(player_name,player_password,player_score+5)); } public void scoredown() {     helper.playerupdate(new player(player_name,player_password,player_score-5)); } 

i getting logcat error like:

failed read row 0, column 1 cursorwindow has 1 rows, 1 columns. fatal exception: main java.lang.illegalstateexception: not execute method of activity caused by: java.lang.illegalstateexception: couldn't read row 0, col 1 cursorwindow.   make sure cursor initialized correctly before accessing data it. 

thanks.

solved:

there has been query causes specific exception , found out.

the exception comes accessing cursor columns , code posted doesn't show that.

however, column indexing starts 0, access first column value string, use getstring(0) instead of getstring(1).


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

how to receive file in java(servlet/jsp) -