android - SQLite keeps returning error from CursorWindow (failed to read row) -


i've been trying solve night long , can't find solution. keep getting following error:

05-15 02:02:39.685    8757-8757/com.financeiro.coolkey.financeiro_2 e/cursorwindow﹕ failed read row 0, column -1 cursorwindow has 4 rows, 7 columns. 05-15 02:02:39.686    8757-8757/com.financeiro.coolkey.financeiro_2 d/androidruntime﹕ shutting down vm 05-15 02:02:39.687    8757-8757/com.financeiro.coolkey.financeiro_2 e/androidruntime﹕ fatal exception: main     process: com.financeiro.coolkey.financeiro_2, pid: 8757     java.lang.illegalstateexception: couldn't read row 0, col -1 cursorwindow.  make sure cursor initialized correctly before accessing data it.             @ android.database.cursorwindow.nativegetstring(native method)             @ android.database.cursorwindow.getstring(cursorwindow.java:438)             @ android.database.abstractwindowedcursor.getstring(abstractwindowedcursor.java:51)             @ dao.calculosdao.criarcalculadora(calculosdao.java:46)             @ dao.calculosdao.exibirprodutosporid(calculosdao.java:170)             @ tabs.detalhesclientecalculos.onactivitycreated(detalhesclientecalculos.java:65)             @ android.support.v4.app.fragment.performactivitycreated(fragment.java:1512)             @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:962)             @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1121)             @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682)             @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1484)             @ android.support.v4.app.fragmentmanagerimpl.executependingtransactions(fragmentmanager.java:482)             @ android.support.v4.app.fragmentpageradapter.finishupdate(fragmentpageradapter.java:141)             @ android.support.v4.view.viewpager.populate(viewpager.java:1073)             @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:555)             @ android.support.v4.view.viewpager.setcurrentiteminternal(viewpager.java:514)             @ android.support.v4.view.viewpager.setcurrentitem(viewpager.java:495)             @ com.financeiro.coolkey.view.detalhesclientetabbed.ontabselected(detalhesclientetabbed.java:78)             @ android.support.v7.app.actionbarimplics$tabwrapper.ontabselected(actionbarimplics.java:558)             @ com.android.internal.app.windowdecoractionbar.selecttab(windowdecoractionbar.java:624)             @ com.android.internal.app.windowdecoractionbar$tabimpl.select(windowdecoractionbar.java:1200)             @ com.android.internal.widget.scrollingtabcontainerview$tabclicklistener.onclick(scrollingtabcontainerview.java:546)             @ android.view.view.performclick(view.java:4756)             @ android.view.view$performclick.run(view.java:19749)             @ android.os.handler.handlecallback(handler.java:739)             @ android.os.handler.dispatchmessage(handler.java:95)             @ android.os.looper.loop(looper.java:135)             @ android.app.activitythread.main(activitythread.java:5221)             @ java.lang.reflect.method.invoke(native method)             @ java.lang.reflect.method.invoke(method.java:372)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694) 

i have no clue going on! have reinstalled app, checked database, looked on questions on stackoverflow , still can't find solution. please help! more code analysis:

calculosdao.java

package dao;  import android.content.contentvalues; import android.content.context; import android.database.cursor; import android.database.sqlite.sqlitedatabase; import android.util.log;  import java.util.arraylist; import java.util.list;  import model.calculos;  /**  * created diego on 24/04/2015.  */ public class calculosdao {     private databasehelper databasehelper;     private sqlitedatabase database;      public calculosdao(context context)     {         //abre o banco de dados, evita o erro nullpointerexpection.         databasehelper = new databasehelper(context);         database = databasehelper.getwritabledatabase();     }      private sqlitedatabase getdatabase()     {         if (database == null)             database = databasehelper.getwritabledatabase();          return database;     }      //fecha o banco de dados.     public void fechar()     {         databasehelper.close();         database = null;     }      private calculos criarcalculadora(cursor cursor)     {         calculos model = new calculos                 (                         cursor.getint(cursor.getcolumnindex(databasehelper.calculos._id)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.id_cliente)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.id_produto)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.equacao)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.resultado)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.obs)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.tipo)),                         cursor.getstring(cursor.getcolumnindex(databasehelper.calculos.dt_criacao))                 );         return model;     }       public list<calculos> listarcalculadora()     {         cursor cursor = getdatabase().query(databasehelper.calculos.tabela,                 databasehelper.calculos.colunas, null, null, null, null, null);          list<calculos> calculos = new arraylist<calculos>();         while(cursor.movetonext())         {             log.d("check__me_listar", "ch: "+calculos +"\\"+cursor);             calculos model = criarcalculadora(cursor);             calculos.add(model);         }          cursor.close();         return calculos;     }      /* code */      //procua todos os ids     public list<calculos> exibirprodutosporid(int id)     {         cursor cursor = getdatabase().query(databasehelper.calculos.tabela,                 databasehelper.calculos.colunas, "id_produto = ?",                 new string[]{ integer.tostring(id) }, null, null, null);          list<calculos> calculos = new arraylist<calculos>();          while(cursor.movetonext())         {             log.d("check__me_exibirprod", "checking: "+calculos);             calculos model = criarcalculadora(cursor);             calculos.add(model);         }            cursor.close();         return calculos;     } } 

detalhesclientecalculos.java

package tabs;  import android.content.context; import android.os.bundle; import android.support.v4.app.listfragment; import android.util.log; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.listview;  import com.financeiro.coolkey.view.detalhesclientetabbed; import com.financeiro.coolkey.view.r;  import java.util.arraylist; import java.util.list;  import adapter.detalhesclientescalculosadapter; import dao.calculosdao; import dao.produtodao; import model.calculos; import model.produto;  /**  * created diego on 30/04/2015.  */ public class detalhesclientecalculos extends listfragment {      private produtodao produtodao;     private listview lista;     //private detalhesclientecalculosadapter dccadapter;     private detalhesclientescalculosadapter dccadapter;     private list<produto> produtoitems;      private calculosdao calculosdao;     private list<calculos> calculositems;       @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {            return inflater.inflate(r.layout.activity_detalhes_cliente_calculos, null, false);         //view rootview = inflater.inflate(r.layout.activity_detalhes_cliente_calculos, null, false);         //         //return rootview;     }      @override     public void onactivitycreated(bundle savedinstancestate) {          super.onactivitycreated(savedinstancestate);          context context = getactivity();         calculosdao = new calculosdao(context);          calculositems = new arraylist<calculos>();         calculositems = calculosdao.exibirprodutosporid(detalhesclientetabbed.cliente_id);          dccadapter = new detalhesclientescalculosadapter(getactivity(),calculositems);         setlistadapter(dccadapter);      } } 

databasehelper.java

db.execsql("create table calculos (_id integer primary key autoincrement, "         + "id_cliente text, "         + "id_produto text, "         + "equacao text, "         + "resultado text, "         + "obs text, "         + "tipo text, "         + "dt_criacao text not null"         + ")");  public static class calculos {     public static final string  tabela = "calculos";  public static final string _id = "_id";  public static final string id_cliente = "id_cliente"; public static final string id_produto = "id_produto"; public static final string equacao = "equacao"; public static final string resultado = "resultado"; public static final string obs = "obs"; public static final string tipo = "tipo"; public static final string dt_criacao = "dt_criacao";  public static final string[] colunas =         {                 _id,                 id_cliente,                 id_produto,                 equacao,                 resultado,                 obs,                 dt_criacao,         }; } 

thank :)

you reading 1 column less , trying value cursor.

public static final string[] colunas =     {             _id,             id_cliente,             id_produto,             equacao,             resultado,             obs,             dt_criacao,     }; 

in above array column public static final string tipo = "tipo"; missing. add array should work.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -