android - NullPointerException while opening database through a fragment -


i trying populate listfragment 1 of columns in database. trying use

    @override     public void onactivitycreated(bundle savedinstancestate) {     super.onactivitycreated(savedinstancestate);          db.open();         db = new notesdatabase(getactivity());         c = db.getallrows();      getactivity().startmanagingcursor(c);      string[] fromfield = new string[] { notesdatabase.key_title };     int[] toview = new int[] { r.id.item_title };     simplecursoradapter mycadapter = new simplecursoradapter(getactivity(),             r.layout.list_item, c, fromfield, toview, 0);     setlistadapter(mycadapter); } 

but dont know why getting nullpointerexception on db.open(); , c = db.getallrows();

db.open()     public notesdatabase open() {     db = mydbhelper.getwritabledatabase();     return this;     } 

db.getallrows();

    public cursor getallrows() {     string = null;     cursor c = db.query(true, database_table, all_keys, where, null, null,             null, null, null);     if (c != null) {         c.movetofirst();     }     return c;     } 

dbhelper

    private static class databasehelper extends sqliteopenhelper {     databasehelper(context context) {         super(context, database_name, null, database_version);     } 

or if there better better way populate list view of fragment database? in advance :)

        db.open();         db = new notesdatabase(getactivity());         c = db.getallrows(); 
  1. open database
  2. create database
  3. get rows.

logically speaking. create first. open. rows. swithc line 1 , lone 2.

another thing , assume getting npe @ mydbhelper, because never created helper.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -